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

Boehm, Hans hans.boehm at hp.com
Wed Mar 15 21:59:34 GMT 2006


The current proposal is to let all data races "break the laws of
physics".  And that's fairly critical to making this work.

Consider T1 which allocates a C++ object with virtual functions, and a
stores a pointer to it in shared variable p, which was initially zero.
If T2 executes

if (p != 0) p -> virtual_fn();

the program may do anything whatsoever, since the call is not guaranteed
to see an initialized vtable, and hence this may branch to anywhere in
the address space.

The alternative would result in memory fences in constructors on many
architectures, which would probably be painful, for minimal benefit.  To
fix this, you need to access p with atomic operations, which seems
reasonable.

Hans

> -----Original Message-----
> From: Nick Maclaren [mailto:nmm1 at cus.cam.ac.uk] 
> Sent: Saturday, March 11, 2006 3:14 AM
> To: C++ threads standardisation; Boehm, Hans
> Subject: Re: [cpp-threads] RE: volatile, memory models, threads 
> 
> Oops.  Sorry.  I am in the middle of an evil task 
> (unrelated), and misspoke.
> 
> > > Thus there is clearly a race here, as there was always 
> intended to be.
> >
> > No, because your previous statement is false.  There is NOT 
> "clearly"
> > a data race.  ...
> 
> What I actually MEANT by that was that that there is not 
> "clearly" a data race of the sort that renders the whole 
> program undefined behaviour.  The problem here is that (even 
> in C++) there is no clear distinction between undefined 
> behaviour that leads merely to unpredictable values and that 
> which the standard allows to break the laws of physics.
> 
> As Hans said, there is clearly a data race of some sort - I 
> didn't mean to contradict that and say that THAT was false.  
> Apologies again.
> 
> 
> 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