[cpp-threads] Relaxed reload example

Raul Silvera rauls at ca.ibm.com
Thu Aug 2 01:43:23 BST 2007



Herb wrote on 08/01/2007 05:53:22 PM:

> The following question came up in the context of IA64, but I thought
> it was worth repeating here to see what the C++MM answer is supposed
> to be. (I?m not sure the latest syntax for a relaxed load in thread
> 2, so I made up something hopefully close.)
>
> Initially:
>   atomic<int*> s = 0;
>
> Thread 1:
>   r1 = new int;
>   *r1 = 55;
>   s = r1; // release
>
> Thread 2:
>   r2 = s.load( memory_order_relaxed ); // not acquire
>   r3 = *r2; // not acquire
>
> Is it possible that (r2 != 0 && r3 != 55)? I?m not sure if the
> reload that would permit that to happen is allowed. Is it?

In the current model this outcome is allowed. However, in virtually all
current architectures this outcome is guaranteed not to occur; this is
basically dependence-based ordering, which we have proposed to include and
Paul is working on a detailed proposal.

At the compiler level, the duplication of atomic loads is disallowed;
however that is insufficient to ensure that this outcome cannot occur.

>
> Herb
>


--
Raúl E. Silvera         IBM Toronto Lab   Team Lead, Toronto Portable
Optimizer (TPO)
Tel: 905-413-4188 T/L: 969-4188           Fax: 905-413-4854
D2/KC9/8200/MKM





More information about the cpp-threads mailing list