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

Nick Maclaren nmm1 at cus.cam.ac.uk
Sun Mar 5 16:21:11 GMT 2006


"Peter Dimov" <pdimov at mmltd.net> 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.

The same thread, for the reason you give.

> > 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.

That is one viewpoint; there are others.  I am nailing my colours
to the fence, and don't give a damn as long as there is a sane,
clear specification.

> 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. 

Precisely.  That was my point.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list