On Friday, 11 March 2016 at 17:03:38 UTC, Anonymouse wrote:
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.

That's why inside of `synchronized` block you can see `if (!instance_)`.

Watch this for details: https://www.youtube.com/watch?v=yMNMV9JlkcQ&t=27m54s

Reply via email to