[Issue 10165] No syntax to create thread-local shared variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 24 16:22:32 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10165



--- Comment #5 from IdanArye <GenericNPC at gmail.com> 2013-05-24 16:22:30 PDT ---
(In reply to comment #4)
> (In reply to comment #0)
> >  But we do need a way to create thread-local shared variables.
> 
> Why? What is the motivating example?

I'm implementing the low lock singleton -
http://forum.dlang.org/thread/pelhvaxwjzhehdjtpsav@forum.dlang.org - as part of
my `std.idioms` library -
http://forum.dlang.org/thread/fofbrlqruxbevnxchxdp@forum.dlang.org - in both
`shared` and `__gshared` versions(I also have a thread-local(=`static`)
version, but it doesn't use the low lock implementation)

A small optimization in the implementation is instead of using a thread-local
boolean indicator to determine if the singleton has been initialized yet, to
save a thread-local reference to the actual instance object. That way, instead
of accessing the memory twice(once to check the indicator and once to fetch the
object) we only need to access it once.

Now, doing it in the `__gshared` version was straight-forward, but the `shared`
version posed a problem - the need to have a thread-local reference to a shared
object - hence this bug report and pull request.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list