[cpp-threads] Yet another visibility question

Peter Dimov pdimov at mmltd.net
Mon Oct 9 13:52:24 BST 2006


Alexander Terekhov wrote:
> On 10/8/06, Peter Dimov <pdimov at mmltd.net> wrote:
>> 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?
>
> Uhmm, it will pass under classic RC model. The store to y in thread 1
> is allowed to be made visible with respect to any other thread only
> after the preceding store to x is made globally visible.

Yeah. But if the store to x is guaranteed to be made visible only to threads 
that observe the subsequent store_release to y, T3 is not guaranteed to see 
it, because it didn't observe T1's store to y, but rather T2's. 




More information about the cpp-threads mailing list