07-May-2013 23:49, Andrei Alexandrescu пишет:
On 5/7/13 12:46 PM, Steven Schveighoffer wrote:
On Tue, 07 May 2013 12:30:05 -0400, deadalnix <[email protected]>
wrote:

[snip]

That is incorrect as the thread not going into the lock can see a
partially initialized object.

The memory barrier prevents that. You don't store the variable until the
object is initialized. That is the whole point.

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.

Exactly.


Returning to the confusing point.

On x86 things are actually muddied by stronger then required hardware guarantees. And only because of this there no need for explicit read barrier (nor x86 have one) in this case. Still the read operation has to be marked specifically (volatile, asm block, whatever) to ensure the _compiler_ does the right thing (no reordering of across it).


--
Dmitry Olshansky

Reply via email to