[cfe-commits] [PATCH] atomic operation builtins, part 1

Jeffrey Yasskin jyasskin at google.com
Tue Oct 11 23:49:51 PDT 2011


On Tue, Oct 11, 2011 at 7:53 PM, Andrew MacLeod <amacleod at redhat.com> wrote:
>   I'm not even sure how to do a 3 byte lock free atomic write short of load,
> mask, compare and swap loop. It reeks of the bitfield data race crud.  Let
> the library take care of it, or maybe even dissallow it...   thoughts?  My
> first instinct is to just pass it on to the library to handle...

Given:

struct WeirdSize {
  char space[3];
};

My thought was that sizeof(atomic<WeirdSize>) should ==4. C++11 says,
"The representation of an atomic specialization need not have the same
size as its corresponding argument type. Specializations should have
the same size whenever possible, as this reduces the effort required
to port existing code." [atomics.types.generic]p9, which recommends
against this, but allows it.

I think it's reasonable for either the C++ library or _Atomic(T) to do
this rounding, and for the atomic intrinsics to either demand
normal-sized arguments (be undefined/error if not) or pass
unusual-size arguments to the ABI library, but I don't have strong
opinions about this.

Jeffrey




More information about the cfe-commits mailing list