Attitional Atomics Errata

ISO/IEC JTC1 SC22 WG14 N1477 – 2010-05-25

Paul E. McKenney,


This document lists some additional errata in the specification of the atomics in the current working draft (n1425, along with proposed wording for their correction.


The list of errata is as follows:

  1. C-language unions must be prohibited from containing atomic members, given that it is not possible to provide constructors for unions in the C language.
  2. The example of weak compare-and-exchange needs to actually use the weak form of the primitive.


Section 6.7.3p2

This paragraph needs to add the prohibition against atomic members of unions:

A union can have member functions (including constructors and destructors), but not virtual (10.3) functions. A union shall not have base classes. A union shall not be used as a base class. If a union contains a non-static data member of reference type the program is ill-formed. If a union contains a member of atomic type, either directly or recursively, the program is ill-formed. At most one non-static data member of a union may have a brace-or-equal-initializer. [ Note: if any non-static data member of a union has a non-trivial default constructor (12.1), copy constructor (12.8), move constructor (12.8), copy assignment operator (12.8), move assignment operator (12.8), or destructor (12.4), the corresponding member function of the union must be user-provided or it will be implicitly deleted (8.4.3) for the union. — end note ]


The example in this paragraph uses a function atomic_compare_exchange() that is not defined in this standard. This needs to change to use atomic_compare_exchange_weak() as shown below:

EXAMPLE: A consequence of spurious failure is that nearly all uses of weak compare-and-exchange will be in a loop.

expected = atomic_load(&current);
do desired = function(expected);
while (!atomic_compare_exchange_weak(&current, &expected, desired));

When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable.