31-Jan-2014 17:26, Stanislav Blinov пишет:
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) {
//(3)
_instance = new AtomicSingleton;
}
} // <- this is 'release'
//(4)
// This store cannot be moved to positions (1) or (2) because
// of 'synchronized' above
atomicStore!(MemoryOrder.raw)(_instantiated, true);
}
No it's not - the second thread may get to (3)
while some other thread is at (4).
--
Dmitry Olshansky