[cpp-threads] Yet another visibility question

Peter Dimov pdimov at mmltd.net
Wed Nov 22 10:31:52 GMT 2006


Boehm, Hans wrote:

>> I don't think I was depending on the order.  To recap, the example is
>>
>> // x y z initially zero
>> // thread 1
>> x = 1; fetch_add_release( &z, +1 );
>> // thread 2
>> y = 1; fetch_add_release( &z, +1 );
>> // thread 3
>> if( load_acquire( &z ) == 2 ) assert( x == 1 && y == 1 );
>>
>> For the if condition to be true, both releases must have
>> occurred and the new values of x and y should be visible.
>> There is no dependence on their order, only that they both
>> occurred.  Am I missing something?
>>
> Not really.  But the whole notion of the fetch_add_releases "occurring
> before" the load_acquire isn't something we can easily express.  We
> clearly don't have a notion of time, since that would imply a total
> ordering that we don't want here.

A per-thread notion of time doesn't imply a total ordering. In thread 3's 
time, the two stores occur before the load. The load observes the effects of 
both stores, even though it can only read one of the values. A similar 
example can be constructed with fetchor:

// x y z initially zero

// thread 1
x = 1; fetch_or_release( &z, 1 );

// thread 2
y = 1; fetch_or_release( &z, 2 );

// thread 3
if( load_acquire( &z ) == 3 ) assert( x == 1 && y == 1 );

Here, again, the load observes the effect of both stores, and it should 
introduce sync-with edges to both. 




More information about the cpp-threads mailing list