On Monday, 4 February 2019 at 10:17:53 UTC, bauss wrote:
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote:

[...]

Here's the singleton code I've been playing with:

[...]
        static bool instantiated_;

        // Thread global
        __gshared DSingleton instance_;
[...]
                if(!instantiated_)
[...]
                                if(!instance_)

[...]

Ex. you state "instantiated_" is thread-local but that's the flag you use to check whether it has been instantiated.

User angel has pointed to https://davesdprogramming.wordpress.com/ and the talk https://www.youtube.com/watch?v=ZHmIAdlNtiM which entails the reasoning about that pattern.

That will not work.

Will it not work in therory (in which?) or in practice (in which)?

Instead it should actually be shared, especially because you use it in a synchronized statement.

The purpose of the pattern is to avoid synchronisationin all but the first call to get().

Also:

DSingleton singleton = new DSingleton;

Defeats the purpose of singleton.

Sure, but it is not lazy.


Reply via email to