[cpp-threads] Visibility question

Peter Dimov pdimov at mmltd.net
Thu Aug 3 09:52:36 BST 2006


Boehm, Hans wrote:

> Without the synchronization edge, the outcome is just plain weird.

Here's another similar example under which there is a race:

T1:

w = 1; // ordinary store

pthread_mutex_lock Ym
y.fetch_add<raw>(1);
pthread_mutex_unlock Ym

x.store<raw>(1);

T2:

r2 = x.load<raw>();

pthread_mutex_lock Zm
z.fetch_add<raw>(1);
pthread_mutex_unlock Zm

if (r2) r1 = w;

So one could rationalize the presence of a race in the original example. 
However, if <ordered> works in this way, it probably should be called 
<ordered>.

Another example that may be of interest is the classic

T1:
x.store<ordered>(1);
r1 = y.load<ordered>();

T2:
y.store<ordered>(1);
r2 = x.load<ordered>();

If r1 == r2 == 0 is possible, <ordered> seems like a misnomer.

N2047 doesn't allow <ordered> load or store, but the same principle seems to 
hold for:

T1:
x.fetch_add<ordered>(1);
r1 = y.fetch_add<ordered>(0);

T2:
y.fetch_add<ordered>(1);
r2 = x.fetch_add<ordered>(0);




More information about the cpp-threads mailing list