[cpp-threads] Yet another visibility question

Alexander Terekhov alexander.terekhov at gmail.com
Tue Oct 10 08:57:39 BST 2006


On 10/9/06, Peter Dimov <pdimov at mmltd.net> wrote:
> 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.

Wouldn't that mean that T3 can observe y changing from 2 to 1 (instead
of 1 to 2) or somehow it would be guaranteed that T3 can never see y
== 1. I just can't imagine such a model. The sane thing is that
observing this conditional y = 2 (if y == 1) store from T2 is ought to
be as good as observing y = 1 store from T1 regarding x visibility in
T3. It doesn't even have to be a release store (in your example)...

regards,
alexander.



More information about the cpp-threads mailing list