[cfe-dev] atomic intrinsics

John McCall rjmccall at apple.com
Mon Oct 18 14:08:10 PDT 2010


On Oct 18, 2010, at 10:27 AM, Howard Hinnant wrote:

> On Oct 18, 2010, at 1:19 PM, John McCall wrote:
> 
>>> One question about Design A that has yet to be discussed is the possible defaulting of memory orderings in the intrinsics.  This defaulting, if it exists, is described at the very bottom of:
>>> 
>>> http://libcxx.llvm.org/atomic_design_a.html
>>> 
>>> I have no strong feeling either way.  I can easily live with or without the memory order defaults.  But I should either remove the "If desired" from the description (mandating the defaults), or remove the description of the defaults altogether (banning them).  Please weigh in with your opinions.
>> 
>> The defaulting scheme for the two-parameter versions is very complicated and precludes implementing the type-checking for these builtins with a single C++ function declaration.  If we're going to allow defaulting, I think they should both default to 5.
> 
> This would make it very easy to drop into undefined behavior.  For example:
> 
> while (__atomic_compare_exchange_strong(&atomic_obj, &expected, desired, memory_order_acquire))
>    ...
> 
> In the above example, only mem_failure is defaulted (to 5 as you suggest), and this violates the requirement that mem_failure <= mem_success (mem_success is 2).

I understand that.  If this seems too risky, the obvious answer is that we shouldn't provide default arguments on these builtins at all.  If people want a more user-friendly option, they can use the library.

I guess we should implement a warning/error for cases where we can detect that mem_failure > mem_success.

John.





More information about the cfe-dev mailing list