Testing some singleton implementations
Stanislav Blinov
stanislav.blinov at gmail.com
Fri Jan 31 05:26:07 PST 2014
In fact #2, I think it's even safe to pull that store out of the
synchronized block:
// (2)
if (!atomicLoad!(MemoryOrder.raw)(_instantiated))
{
// (1)
synchronized
{ // <- this is 'acquire'
if (_instance is null) {
_instance = new AtomicSingleton;
}
} // <- this is 'release'
// This store cannot be moved to positions (1) or (2)
because
// of 'synchronized' above
atomicStore!(MemoryOrder.raw)(_instantiated, true);
}
More information about the Digitalmars-d
mailing list