[cpp-threads] Alternatives to SC

Peter Dimov pdimov at mmltd.net
Sat Jan 13 22:29:17 GMT 2007


Herb Sutter wrote:

>> Towards TSO, maybe.  In light of the example above, I have a hard
>> time believing they will really get all the way to SC.
>
> One reference I had in mind was:
>
>   "Multiprocessors Should Support Simple Memory Consistency Models"
>   Mark D. Hill, IEEE Computer, August 1998
>   http://citeseer.ist.psu.edu/hill98multiprocessors.html
>
> Mark argues that hardware should implement (not only enable) SC, "or
> in some cases" read reordering.

To which extent this also implies that our compilers need to be SC as well? 
To give you a concrete example:

// (B1)

atomic_fetchadd_raw( &x, 1 );

// (B2)

atomic_fetchadd_raw( &x, 1 );

Here B1 and B2 are blocks of ordinary operations that don't touch x. This 
can be transformed by the compiler to:

// (B1)
// (B2)

atomic_fetchadd_raw( &x, 2 );

which then may enable further optimizations due to B1 and B2 sharing a basic 
block. Imposing sequentially consistent (or CCCC, for that matter) semantics 
on x precludes this trasformation.

And if we agree that we need the option to be able to grant the compiler a 
license to do this sort of thing, why deny the hardware the opportunity to 
also perform similar optimizations? The end result for the program is 
exactly the same.




More information about the cpp-threads mailing list