[cpp-threads] memory model

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


Doug Lea wrote:
> Peter Dimov wrote:
>> Doug Lea wrote:
>>
>>> The now-usual request: Could you flesh out your alternative into an
>>> informal proposal and show it in common examples so people
>>> can decide whether to pursue it?
>>
>> I'll try, but this is not strictly relevant to the discussion at
>> hand. It is already agreed that some mechanism of specifying
>> finer-grained atomic operations should be available (right?), and
>> the question is whether a qualifier-based approach should be
>> provided in addition to this mechanism.
>
> Mostly so. But among the motivations for qualifier is that
> the library versions will be difficult to learn, error-prone
> to use, and uncheckable for consistency by compilers. If we
> find an alternative that doesn't have these problems, then we
> ought to reconsider it.

OK.

I have in mind something along these lines:

template<class T, class Msync> T atomic_load( Msync msync, T * addr );

where T is a POD type and msync is as described by Alexander.

The functions are specified in way that makes them implementable as C 
compiler intrinsics.

T is not required to be tagged with atomic<> because C people hate template 
syntax.

msync is an argument and not a suffix of the function to allow combinations 
of the form msync_hsb + msync_hlb and so on.

Aligning addr on cache line boundary or making sure that it doesn't share a 
cache line with another addr when this is required by the architecture is up 
to the user.

- Difficult to learn:

Yes. I maintain that learning to use either approach _correctly_ is 
difficult.

- Error prone:

Yes. A qualifier approach is also error-prone. This can't be designed out.

- Checkable by compiler:

More checkable than volatile. The actual constraint is explicitly specified 
and the compiler can verify the programmer's assumptions. With a qualifier 
the compiler is forced to trust the programmer and infer the necessary 
constraints. This can result in code that does not do what the programmer 
expected it to do. 





More information about the cpp-threads mailing list