Iterating over thread local storage variables

Anonymouse via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 11 09:03:38 PST 2016


On Friday, 11 March 2016 at 15:21:38 UTC, maik klein wrote:
>     static Singleton!T get()
>     {
>         if (!instantiated_)
>             {
>             synchronized(Singleton!T.classinfo){
>                 if (!instance_){
>                     instance_ = new Singleton!T();
>                 }
>                 instantiated_ = true;
>                 instance_.tls.insertBack(&instance_.value);

As a drive-by comment, mind that there is a race there. 
_instantiated may have been set after the if statement but before 
the synchronized block. You have to test it again inside.


More information about the Digitalmars-d-learn mailing list