Low-Lock Singletons In D

Dmitry Olshansky dmitry.olsh at gmail.com
Tue May 7 12:58:34 PDT 2013


07-May-2013 17:25, Andrei Alexandrescu пишет:
> On 5/7/13 2:50 AM, Mehrdad wrote:
>> On Monday, 6 May 2013 at 18:46:56 UTC, Andrei Alexandrescu wrote:
>>> Any concurrent operation (in this case read from one thread and write
>>> from another) requires a handshake between threads, most often in the
>>> form of an release write coupled with an acquire read. Whenever the
>>> handshake is absent but concurrent operations on shared memory do
>>> occur, the code is broken. The beauty of the TLS-based pattern is that
>>> in the steady state there's no need for a shared read and handshake.
>>>
>>> Andrei
>>
>>
>>
>> Hmm, are you referring to the same lack of a barrier that the others are
>> also referring to?
>>
>>
>> As far as I can see, there shouldn't be a need for any other handshake
>> in this example.
>>
>> As long as the object is fully initialized before _static is written to
>> (easy enough with just a memory barrier), there is no penalty for
>> subsequent reads whatsoever.
>>
>> Right?
>
> No. A tutorial on memory consistency models would be too long to insert
> here. I don't know of a good online resource, does anyone?
>

Sutter's Mill is a good starting point even though it's C++ biased.

Two recent insightful talks on C++11 memory model with down and dirty 
details:

http://herbsutter.com/2013/02/11/atomic-weapons-the-c-memory-model-and-modern-hardware/


-- 
Dmitry Olshansky

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list