[Sbcl-devel] thread local variables

42 views
Skip to first unread message

Gábor Melis

unread,
Dec 10, 2015, 2:06:00 PM12/10/15
to sbcl-devel
Here is an implementation of thread local variables (for
https://bugs.launchpad.net/sbcl/+bug/310204):

https://github.com/melisgl/sbcl/commits/thread-local

See the commit message and the diff to the documentation but the gist
of it is this:

(defmacro define-thread-local (var &optional (val nil valp) (doc nil docp))
"Define a special variable at the top level like DEFVAR with the
following differences. If VAR is globally unbound and VAL is specified
then set VAR's global binding to VAL. Also, make it so, by declaring
VAR THREAD-LOCAL, that if the global binding were to be changed (by
SETQ, SET, or (SETF SYMBOL-VALUE)), then a thread local top level
binding is created for the current thread. Note that prior to getting
their own top level binding, threads can see the global binding, but
they cannot change it unless they resort to (SETF
SYMBOL-GLOBAL-VALUE)."
...)

Reviews, comments, ports to x86 and arm64 are most welcome.

Cheers,
Gabor

------------------------------------------------------------------------------
_______________________________________________
Sbcl-devel mailing list
Sbcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-devel

Stas Boukarev

unread,
Dec 10, 2015, 4:05:11 PM12/10/15
to Gábor Melis, sbcl-devel
On Thu, Dec 10, 2015 at 10:04 PM, Gábor Melis <me...@retes.hu> wrote:
> Here is an implementation of thread local variables (for
> https://bugs.launchpad.net/sbcl/+bug/310204):
>
> https://github.com/melisgl/sbcl/commits/thread-local
>
> See the commit message and the diff to the documentation but the gist
> of it is this:
>
> (defmacro define-thread-local (var &optional (val nil valp) (doc nil docp))
> "Define a special variable at the top level like DEFVAR with the
> following differences. If VAR is globally unbound and VAL is specified
> then set VAR's global binding to VAL. Also, make it so, by declaring
> VAR THREAD-LOCAL, that if the global binding were to be changed (by
> SETQ, SET, or (SETF SYMBOL-VALUE)), then a thread local top level
> binding is created for the current thread. Note that prior to getting
> their own top level binding, threads can see the global binding, but
> they cannot change it unless they resort to (SETF
> SYMBOL-GLOBAL-VALUE)."
> ...)
>
> Reviews, comments, ports to x86 and arm64 are most welcome.
I assume PPC needs an adjustment as well?

And an analogy that helped me see the difference with special is that it
basically does copy-on-write.

In the macro, instead of checking for VALP at run-time and passing it doing
what DEFVAR does would produce better expansion and will reduce fasl size
(not really important), if only for consistency.

--
With best regards, Stas.

Gábor Melis

unread,
Dec 11, 2015, 12:42:29 AM12/11/15
to Stas Boukarev, sbcl-devel
On Thu, Dec 10, 2015 at 9:03 PM, Stas Boukarev <stas...@gmail.com> wrote:
> On Thu, Dec 10, 2015 at 10:04 PM, Gábor Melis <me...@retes.hu> wrote:
>> Here is an implementation of thread local variables (for
>> Reviews, comments, ports to x86 and arm64 are most welcome.
> I assume PPC needs an adjustment as well?

Oh, yes. PPC too.

> And an analogy that helped me see the difference with special is that it
> basically does copy-on-write.

Yes, copy-on-write on the global binding.

> In the macro, instead of checking for VALP at run-time and passing it doing
> what DEFVAR does would produce better expansion and will reduce fasl size
> (not really important), if only for consistency.

Thanks. Done.

Not sure what's the best way to go about updating the rest of the platforms.
I'm hoping for volunteers. I should be able to tackle x86 but currently the
multiarch i386 build fails even on stock SBCL with a memory fault in warm init.
Does anyone have a recipe how to build x86 SBCL on x86-64?

Christophe Rhodes

unread,
Dec 11, 2015, 9:15:57 AM12/11/15
to Gábor Melis, sbcl-devel
Gábor Melis <me...@retes.hu> writes:

> Not sure what's the best way to go about updating the rest of the platforms.
> I'm hoping for volunteers. I should be able to tackle x86 but currently the
> multiarch i386 build fails even on stock SBCL with a memory fault in warm init.
> Does anyone have a recipe how to build x86 SBCL on x86-64?

I just built it here (sbcl-1.3.1.102) with `./make.sh --arch=x86'.

Cheers,

Christophe

Reply all
Reply to author
Forward
0 new messages