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

Nick Maclaren nmm1 at cus.cam.ac.uk
Sat Mar 4 07:32:27 GMT 2006


"Boehm, Hans" <hans.boehm at hp.com> wrote:
>
> Thus the intent was to handle the case of objects being accessed
> atomically and not atomically.  Whether there are any cases in which the
> current model gives counter-intuitive semantics for such a case is less
> clear to me.  After thinking about it a bit, I'm not sure there's a
> problem.  If someone has tricky examples in mind, or suggestions for
> improving the description of the memory model, please post.

Grrk.  Nor am I, but I am equally uncertain about whether there is
NOT a problem.  I really DON'T like allowing this, because it is a
very nasty implementation problem, and the slightest ambiguity in
the specification WILL cause trouble.

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.

Now, this is Bad News on many architectures with loose memory models,
where it is fairly easy to sequentialise actions if they BOTH request
it, but very hard if only one of them does and the other has no
handle to (or knowledge of) the non-atomic access.

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?


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