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);
        }

Reply via email to