[cpp-threads] RE: volatile, memory models, threads

Peter Dimov pdimov at mmltd.net
Sun Mar 5 13:02:17 GMT 2006


Nick Maclaren wrote:

> The problem is that, if an object is accessed atomically via an
> action A and non-atomically via an action B, then A must act as a
> barrier to B, at all levels from the compiler down to the hardware.

Do A and B occur in the same thread or in separate threads? If in separate 
threads, this doesn't impose any ordering and is a data race and hence, 
undefined behavior, if at least one of the actions is a write.

> Furthermore, there are gruesome gotchas with actions like the
> following:
>
> Thread 1:    X = 0x1200
>             *(atomic *)X = 0X0034
> Thread 2:    *(atomic *)X = 0X0045
>
> Is X allowed to end up as 0x1245?  If not, why not?

X should be allowed to end up as an arbitrary value; the program should also 
be allowed to die with a hardware exception. There is a data race between 
the 1200 and 0045 writes.

This is not what the strawman proposal says, though. It says that there is 
no race since at least one of the actions is a synchronization action. I'm 
not sure whether this is deliberate or accidental, and if deliberate, what 
is it supposed to accomplish. 




More information about the cpp-threads mailing list