[cpp-threads] Yet another visibility question
Peter Dimov
pdimov at mmltd.net
Sun Oct 8 13:27:04 BST 2006
Consider:
// initial values 0
// thread 1
x = 1; // ordinary store
store_release( y, 1 );
// thread 2
r1 = load_raw( y ); // assume this reads 1
store_release( y, r1+1 ); // ... and this stores 2
// thread 3
r2 = load_acquire( y ); // assume this reads 2
if( r2 == 2 )
{
assert( x == 1 ); // ordinary load
}
Will the assert pass? Is there a data race on x? What if thread 2's load had
acquire semantics?
Thread 2 can be rephrased as performing
fetchadd_release( y, 1 );
and
fetchadd_ordered( y, 1 );
respectively. Is this an equivalent transformation (from visibility
standpoint, atomicity does not concern us for the moment)?
More information about the cpp-threads
mailing list