[cpp-threads] Yet another visibility question

Peter Dimov pdimov at mmltd.net
Tue Dec 19 18:11:07 GMT 2006


Hans Boehm wrote:

> Otherwise consider a variant of the above example:
>
> r1 = y_initialized.load_raw();
> if (r1) {
>   y.foo();
> } else {
>   y.bar();
> }
>
> Assume that y_initialized is set in another thread after initializing
> y. I'm now in a situation in which this code is correct unless foo()
> and bar() happen to assign the same value to the same field of y.  In
> that case,
> the stores would no longer be dependent, and hence could happen before
> initialization.  But clearly it shouldn't be my business to know how
> foo() and bar() are implemented.

If we assume that foo and bar are opaque, the code is incorrect anyway due 
to a possible data race between the potential reads from y in foo and bar 
and the initialization of y in the other thread. 




More information about the cpp-threads mailing list