[cpp-threads] memory model

Peter Dimov pdimov at mmltd.net
Fri Apr 29 12:15:34 BST 2005


Doug Lea wrote:
> I guess the question here is who we are most afraid of offending:
>
>  * People who would be unhappy that providing semantics for
>    volatile might sometimes make existing usages more expensive
>
>  * People who would be unhappy adding another qualifier
>    to mean "accessible by multiple threads without a lock",
>    (that would in most cases have exactly the semantics
>    of volatile).
>
>  * People who would be unhappy to have to declare every
>    volatile-like variable using atomic templates (which
>    avoids keywords but is programmer-hostile.)

I think that these options do not cover the whole spectrum.

There is also the point of view that

    x = y;

should not implicitly insert unspecified barriers depending on the types of 
x and y and the previous and following operations. That is, the race 
resistancy of "x = y" should not change depending on context (for x and y 
being of a fundamental/POD type; for class types we are obviously at the 
mercy of the class designer.)

Explicit barriers along the lines of

    x = atomic_load_acq( &y );

or

    atomic_store_rel( &x, y );

or

    atomic_store_rel( &x, atomic_load_ccacq( &y ) );

make the intent of the code clearer (and locally verifiable to a certain 
extent, even if the types of x and y come from template parameters.)





More information about the cpp-threads mailing list