[cpp-threads] Examples of cross-thread ordering

Peter Dimov pdimov at mmltd.net
Thu Jul 13 14:15:03 BST 2006


Herb Sutter wrote:

> 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)?

This is a legal local transformation, in my opinion. The hardware is allowed 
to do the same thing using a write queue that can be read from.

x = 1; // store goes into queue
y = 2; // ditto
r1 = y; // r1 reads the value 2 from the write queue

// at some later point the write queue stores reach visibility




More information about the cpp-threads mailing list