[cpp-threads] Examples of cross-thread ordering

Herb Sutter hsutter at microsoft.com
Wed Jul 12 00:48:13 BST 2006


Peter wrote:
> >>> Example 1:
> >>>
> >>>   // thread T1
> >>>   x = 1; // a
> >>>   y = 2; // b
> >>>   r1 = y; // c
> 
> The interesting question here for me is whether b -> c under the C++MM
> because both operate on the same location y. Don't IA64
(ld.acq/st.rel),
> x86
> PO and TSO promise order in this case?

Well, it's not just the processor. A compiler might want to eliminate
the read of y

  x = 1; // a
  y = 2; // b
  r1 = 2; // c

and then

  r1 = 2; // c
  x = 1; // a
  y = 2; // b

Shouldn't that be a legal local transformation, since it only reduces
the set of possible behaviors (by making c be unable to see a racing
update on another thread, which it can't rely on seeing anyway)?

Herb




More information about the cpp-threads mailing list