[cpp-threads] Visibility question

Peter Dimov pdimov at mmltd.net
Fri Aug 4 13:39:19 BST 2006


Peter Dimov wrote:
> 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;

Let's call that platform P1 that has raw and pthread mutexes and implements 
N2047 <ordered> on top.

Here are two more:

P2: has no atomics. Implements even <raw> with a per-location mutex.

P3: has load<acquire> and cas<release> only. Implements fetch_add<ordered> 
with them as:

do
{
    T old = load<acquire>();
} while( !cas<release>( old, old + dt ) );

It seems to me that the example contains a race under all three 
implementations. P3 is more interesting than the other two because it 
(arguably) meets the requirements for N2047's native_atomic. 




More information about the cpp-threads mailing list