[cpp-threads] Failed compare-and-swap

Peter Dimov pdimov at mmltd.net
Thu Aug 2 23:47:42 BST 2007


Lawrence Crowl wrote:

>> compare_swap( int& e, int d, memory_order w, memory_order r );
>>
>> compare_swap( int& e, int d, memory_order w = memory_order_seq_cst )
>> {
>>     compare_swap( e, d, w, w );
>> }
>
> Ah, yes, if you switch the order of parameters.  Hans has already
> said he likes the switched order.  Any other opinions?

Having w at third place in one overload and at fourth place in the other is 
a recipe for trouble IMO.

>> The first overload can be made to strip release from r.
>
> I think that if the parameter is explicit, it should be exactly right.
> We currently require programmers to use the right form, and I'd
> like to leave it that way.

No strong opinion one way or the other. One problem is that you can't really 
validate the argument at compile time, so the path of least resistance (a 
Requires clause) will leave the behavior undefined when an incorrect 
memory_order is supplied. I'm not sure that this is an improvement.

Have I mentioned that different types a-la N2195 allow you to reject the 
invalid constraints at compile time? :-) 




More information about the cpp-threads mailing list