Low-Lock Singletons In D

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue May 7 15:44:27 PDT 2013


On 5/7/13 5:57 PM, Mehrdad wrote:
> On Tuesday, 7 May 2013 at 19:49:30 UTC, Andrei Alexandrescu wrote:
>> A memory barrier is not a one-way thing, i.e. not only the writer must
>> do it. Any operation on shared memory is a handshake between the
>> writer and the reader. If the reader doesn't do its bit, it can see
>> the writes out of order no matter what the writer does.
>>
>> Andrei
>
>
>
> Andrew, I still don't understand:
>
> The writer is ensuring that writes to memory are happening _after_ the
> object is initialized and _before_ the reference to the old object is
> modified, via a memory barrier.

The writer is only half of the equation. The reader has its own cache to 
worry about and its own loading order.

> Unless you're claiming that a memory barrier _doesn't_ do what it's
> supposed to (i.e., the memory module is executing writes out-of-order
> even though the processor is issuing them in the correct order), there
> is no way for _anyone_ to see a partially initialized object anywhere...

I'm not claiming, I'm destroying :o). There is. I know it's confusing. 
You may want to peruse the reading materials linked by others.


Andrei


More information about the Digitalmars-d mailing list