[cpp-threads] Web site updated

Peter Dimov pdimov at mmltd.net
Sat Feb 17 21:46:57 GMT 2007


Raul Silvera wrote:

> In any case, I can agree that "before" could be replaced by
> "no-later-than", in which case the memory operations could be removed.
> However, it cannot be completely transformed into a noop: the fence
> must remain. Here is an example:
>
> a==cnt==0
>
> [1] atomic_store_relaxed(a, 1);
>
> [2] atomic_fetchadd_release( &cnt, r );
> [3] atomic_fetchadd_release( &cnt, -r );
>
> [4] atomic_store_relaxed(cnt, 1);
>
> If you were to replace [23] by a noop, you would lose any ordering
> between [1] and [4], so other threads could see cnt==1, a==0.

You are right; in this case [234] can be fused into a single store_release, 
though. :-)

int a = 0, cnt = 0, *p;

 [1] atomic_store_relaxed( &a, 1 );

 [2] atomic_fetchadd_release( &cnt, r );
[3] atomic_fetchadd_release( &cnt, -r );

 [4] atomic_store_relaxed( p, 1 );

Here potential aliasing between *p and cnt comes into play and [23], if 
combined, must produce a fetchadd_release with 0 or a release fence. 




More information about the cpp-threads mailing list