[cpp-threads] Implicit Synchronization

Boehm, Hans hans.boehm at hp.com
Tue Jul 11 22:45:16 BST 2006


> -----Original Message-----
> From: Lawrence Crowl
> 
> On 7/11/06, Boehm, Hans <hans.boehm at hp.com> wrote:
> > We currently propose to have assignment translate to a 
> store<release> 
> > and conversion to the base type to translate to a 
> load<acquire>.  Thus 
> > double-checked locking should just work so long as the flag 
> or pointer 
> > is atomic.
> 
> This statement is inconsistent with what I thought was going on.
> I thought the semantics of store release were for the one 
> variable, not all variables.  Am I wrong?
> 
> That is, given an atomic boolean guarding an integer,
> 
> global data:    int x = 3; atomic<bool> b = false;
> thread one:     x = 4;  b = true /* store release */;
> thread two:     while ( ! b /* load acquire */ ); int y = x;
> 
> is it that y must be four?
Yes.  In this sense it applies to all variables, as it does in Java.

There is an orthogonal question as to whether any ordering is guaranteed
if the two threads access unrelated synchronization objects, e.g.:

(x, y atomic, assume unordered operations though it doesn't matter with
current proposal, initially zero)
Threads 1:
x = 1;
lock(l1); unlock(l1);
lock(l1); unlock(l1);
r1 = y;

Threads 2:
y = 1;
lock(l2); unlock(l2);
lock(l2); unlock(l2);
r2 = x;

Can r1 = r2 = 0?

The original C++ proposal left this up to the library definition.  But I
think the answer has to be that this outcome is possible, as it is in
Java with ordinary, non-volatile variables. 

Hans
 
> Similar questions apply to variables guarded by full-up locks.



More information about the cpp-threads mailing list