[cpp-threads] Yet another visibility question
Peter Dimov
pdimov at mmltd.net
Wed Nov 22 11:06:35 GMT 2006
Peter Dimov wrote:
> // 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.
A logical progression of this example is:
// x y z initially zero
// thread 1
x = 1; store_release( &z, 1 );
// thread 2
if( load_raw( &z ) == 1 )
{
y = 1; store_release( &z, 2 );
}
// thread 3
if( load_acquire( &z ) == 2 ) assert( x == 1 && y == 1 );
This actually brings us back to one of your earlier examples:
// x y z w initially zero
// thread 1
x = 1; store_release( &z, 1 );
// thread 2
if( load_raw( &z ) == 1 )
{
y = 1; store_release( &w, 1 );
}
// thread 3
if( load_acquire( &w ) == 1 ) assert( x == 1 && y == 1 );
where the two stores are separated into distinct variables, but the behavior
probably ought to be the same. One way of making the assert pass is to have
a raw->release edge in this case. An alternative is to introduce an acq->rel
edge from the w load to the z store for causality reasons - somehow.
More information about the cpp-threads
mailing list