[cpp-threads] Yet another visibility question

Alexander Terekhov alexander.terekhov at gmail.com
Mon Oct 9 09:37:07 BST 2006


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. Additional
store to y in thread 2 doesn't change anything.

r2 = load_acquire( y );

if( r2 )
{
    assert( x == 1 ); // ordinary load
}

regards,
alexander.



More information about the cpp-threads mailing list