[cpp-threads] Relaxed reload example
Paul E. McKenney
paulmck at linux.vnet.ibm.com
Thu Aug 2 01:20:11 BST 2007
On Wed, Aug 01, 2007 at 03:16:49PM -0700, Herb Sutter wrote:
> > DEC Alpha would in fact permit this outcome.
>
> Why doesn't that surprise me? :-)
;-)
> > I am not aware of any other CPU that permits this outcome.
>
> I was more specifically wondering what the draft C++MM said about it. At
> least one subquestion would be whether relaxed reads can be replicated
> (by the CPU, or the compiler, etc.). Not sure if there are other ways
> the result could happen.
The current C++MM does in fact allow this outcome. N2260 proposes
adding mechanism that permits the programmer to disallow this outcome
without incurring the overhead of an explicit fence. There will be a
new version of this document soon.
This outcome could happen on non-Alpha platforms via value speculation
and other similar compiler optimizations. The order of events might
be as follows:
T1. Correctly guess the value of the not-yet-assigned pointer.
T1. Dereference the guess, pick up uninitialized fields from the
structure.
T2. Initialize the fields in the structure.
T2. Store-release the pointer to the new structure.
T1. Validate the guessed value for the pointer. Since they
match, incorrectly conclude that the dereference operation
went smoothly.
Can't say that I am a fan of such optimizations, but others disagree.
Thanx, Paul
More information about the cpp-threads
mailing list