On Friday, 11 March 2016 at 17:33:43 UTC, sigod wrote:
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_)`.
It does, yes, but it also calls instance_.tls.insertBack
unconditionally. To illustrate:
http://dpaste.dzfl.pl/8f3e78f3265a7
Apologies for derailing.