<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<title>Adjusting C++ Atomics for C Compatibility</title>
</head>

<body>
<h1>Adjusting C++ Atomics for C Compatibility</h1>

<p>
ISO/IEC JTC1 SC22 WG21 N3164 = 10-0154 - 2010-10-14
</p>

<p>
Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org
</p>

<p>
<a href="#Introduction">Introduction</a><br>
<a href="#Wording">Wording</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.general">29.1 General [atomics.general]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.syn">29.2 Header <code>&lt;atomic&gt;</code> synopsis [atomics.syn]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.types">29.5 Atomic Types [atomics.types]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.types.integral">29.5.1 Integral Types [atomics.types.integral]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.types.address">29.5.2 Address Type [atomics.types.address]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.types.generic">29.5.3 Generic Type [atomics.types.generic]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.types.operations">29.6 Operations on Atomic Types [atomics.types.operations]</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#atomics.compatibility">29.9 C Compatibility [atomics.compatibility]</a><br>
</p>

<h2><a name="Introduction">Introduction</a></h2>

<p>
The draft of
<a href="http://www.open-std.org/JTC1/SC22/WG14/">C1X</a>
includes a facility for atomics.
The primary change in this facility in the draft
<a href="http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1494.pdf">N1494</a>
is incorporation of a
<a href="http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1485.pdf">new
atomics proposal</a>
for a <em>productive</em> syntax
for declaring atomic types and operators for atomic types.
(The latest C1X draft is
<a href="http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1516.pdf">N1516</a>.)
C++0x FCD national body comment CA 23 (and more generally US 1)
requests compatibility between C and C++ with respect to atomics.
</p>

<p>
This paper provides normative wording changes
to reflect the choices in 
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2010/n3137.html">
N3137 C and C++ Liaison: Compatibility for Atomics</a>.
</p>

<p>
In summary, the changes are:
</p>

<ul>

<li>
Removed the named <code>atomic_</code>.... types and typdefs,
except for <code>atomic_flag</code>.
Now that C has a productive syntax for naming atomic types,
these names are no longer required.
The <code>atomic_flag</code> type is special,
and is not part of the normal productive atomic syntax.
</li>

<li>
Remove the base-class relationship
between <code>atomic_</code>....  named types
and the corresponding specializations
of the <code>atomic</code> template class.
This change ensures compatibility with C.
Some member functions and operators,
that were formerly inherited from the base class,
must be hoisted from the named types to the specializations.
</li>

<li>
Change the <code>atomic_</code>.... freestanding functions to templates,
as they must now cover arbitrary atomic types
rather than just the named types.
Some specializations are required.
</li>

<li>
Correct some of the wording
around <code>ATOMIC_VAR_INIT</code> and <code>atomic_init</code>.
</li>

<li>
Add a section on C compatibility,
incorporating
the C header <code>&lt;stdatomic.h&gt;</code>,
the macro <code>__STDC_NO_THREADS__</code>,
and a new function macro <code>_Atomic</code>
to serve in the syntactic position of C's type specifier for atomics.
</li>

</ul>


<h2><a name="Wording">Wording</a></h2>

This wording is relative to
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2010/n3126.pdf">
N3126 Working Draft, Standard for Programming Language C++</a>.

<h3><a name="atomics.general">29.1 General [atomics.general]</a></h3>

<p>
Edit table 141 as follows.
</p>
<blockquote>
<table>
<caption>Table 141 &mdash; Atomics library summary</caption>
<thead>
<tr><th>Subclause</th><th>Header(s)</th></tr>
</thead>
<tbody>
<tr><td>29.3  Order and Consistency</td></tr>
<tr><td>29.4  Lock-free Property</td></tr>
<tr><td>29.5  Atomic Types</td><td><code>&lt;atomic&gt;</code></td></tr>
<tr><td>29.6  Operations on Atomic Types</td></tr>
<tr><td>29.7  Flag Type and Operations</td></tr>
<tr><td>29.8  Fences</td></tr>
<tr><td>29.9  C Compatibility</td><td><code>&lt;stdatomic.h&gt;</code></td></tr>
</tbody>
</table>
</blockquote>

<h3><a name="atomics.syn">29.2 Header <code>&lt;atomic&gt;</code> synopsis [atomics.syn]</a></h3>

<p>
Move the <code>ATOMIC_VAR_INIT</code> macro declaration
to its proper order with respect to the sections.
</p>

<p>
Move the <code>atomic_flag</code> type and function declarations
to their proper order with respect to the sections.
</p>

<p>
Remove the declaration block for
<code>atomic_bool</code> and associated functions.
</p>

<p>
Remove the declaration block for
<code>atomic_<var>itype</var></code> and associated functions.
</p>

<p>
Remove the declaration block for
<code>atomic_address</code> and associated functions.
</p>

<p>
Modify the section number for the generic type definitions to 29.5.
</p>

<p>
For section 29.6,
add generic free functions as follows.
The functions mirror C type-generic macros.
</p>

<blockquote><pre><code>
<ins>template &lt;typename Type&gt;
bool atomic_is_lock_free(const volatile atomic&lt;Type&gt;*);
template &lt;typename Type&gt;
bool atomic_is_lock_free(const atomic&lt;Type&gt;*);
template &lt;typename Type&gt;
void atomic_init(volatile atomic&lt;Type&gt;*, iType);
template &lt;typename Type&gt;
void atomic_init(atomic&lt;Type&gt;*, iType);
template &lt;typename Type&gt;
void atomic_store(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
void atomic_store(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
void atomic_store_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
void atomic_store_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_load(const volatile atomic&lt;Type&gt;*);
template &lt;typename Type&gt;
Type atomic_load(const atomic&lt;Type&gt;*);
template &lt;typename Type&gt;
Type atomic_load_explicit(const volatile atomic&lt;Type&gt;*, memory_order);
template &lt;typename Type&gt;
Type atomic_load_explicit(const atomic&lt;Type&gt;*, memory_order);
template &lt;typename Type&gt;
Type atomic_exchange(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_exchange(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_exchange_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_exchange_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
bool atomic_compare_exchange_weak(volatile atomic&lt;Type&gt;*, Type*, Type);
template &lt;typename Type&gt;
bool atomic_compare_exchange_weak(atomic&lt;Type&gt;*, Type*, Type);
template &lt;typename Type&gt;
bool atomic_compare_exchange_strong(volatile atomic&lt;Type&gt;*, Type*, Type);
template &lt;typename Type&gt;
bool atomic_compare_exchange_strong(atomic&lt;Type&gt;*, Type*, Type);
template &lt;typename Type&gt;
bool atomic_compare_exchange_weak_explicit(volatile atomic&lt;Type&gt;*, Type*,
                                           Type, memory_order, memory_order);
template &lt;typename Type&gt;
bool atomic_compare_exchange_weak_explicit(atomic&lt;Type&gt;*, Type*,
                                           Type, memory_order, memory_order);
template &lt;typename Type&gt;
bool atomic_compare_exchange_strong_explicit(volatile atomic&lt;Type&gt;*, Type*,
                                             Type, memory_order, memory_order);
template &lt;typename Type&gt;
bool atomic_compare_exchange_strong_explicit(atomic&lt;Type&gt;*, Type*,
                                             Type, memory_order, memory_order);</ins>
</code></pre></blockquote>

<p>
For section 29.6,
add generic free functions as follows.
These templates are only declared, not defined.
</p>

<blockquote><pre><code>
<ins>template &lt;typename Type&gt;
Type atomic_fetch_add(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_add(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_add_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_add_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_sub(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_sub(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_sub_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_sub_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_and(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_and(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_and_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_and_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_or(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_or(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_or_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_or_explicit(atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_xor(volatile atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_xor(atomic&lt;Type&gt;*, Type);
template &lt;typename Type&gt;
Type atomic_fetch_xor_explicit(volatile atomic&lt;Type&gt;*, Type, memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_xor_explicit(atomic&lt;Type&gt;*, Type, memory_order);</ins>
</code></pre></blockquote>

<p>
For section 29.6,
add the following integral specializations.
</p>

<blockquote>
<p>
For each integral type <code><var>integral</var></code>,
</p>

<pre><code>
<ins>template &lt;&gt;
<var>integral</var> atomic_fetch_add(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_add(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_add_explicit(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_add_explicit(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_sub(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_sub(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_sub_explicit(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_sub_explicit(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_and(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_and(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_and_explicit(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_and_explicit(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_or(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_or(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_or_explicit(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_or_explicit(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_xor(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_xor(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>);
template &lt;&gt;
<var>integral</var> atomic_fetch_xor_explicit(volatile atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);
template &lt;&gt;
<var>integral</var> atomic_fetch_xor_explicit(atomic&lt;<var>integral</var>&gt;*, <var>integral</var>,
                                   memory_order);</ins>
</code></pre></blockquote>

<p>
For section 29.6,
add generic free functions as follows.
These functions correspond to
the <code>atomic</code> class template partial specialization for pointers.
</p>

<blockquote><pre><code>
<ins>template &lt;typename Type&gt;
Type atomic_fetch_add(volatile atomic&lt;Type*&gt;*, ptrdiff_t);
template &lt;typename Type&gt;
Type atomic_fetch_add(atomic&lt;Type*&gt;*, ptrdiff_t);
template &lt;typename Type&gt;
Type atomic_fetch_add_explicit(volatile atomic&lt;Type*&gt;*, ptrdiff_t,
                               memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_add_explicit(atomic&lt;Type*&gt;*, ptrdiff_t,
                               memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_sub(volatile atomic&lt;Type*&gt;*, ptrdiff_t);
template &lt;typename Type&gt;
Type atomic_fetch_sub(atomic&lt;Type*&gt;*, ptrdiff_t);
template &lt;typename Type&gt;
Type atomic_fetch_sub_explicit(volatile atomic&lt;Type*&gt;*, ptrdiff_t,
                               memory_order);
template &lt;typename Type&gt;
Type atomic_fetch_sub_explicit(atomic&lt;Type*&gt;*, ptrdiff_t,
                               memory_order);</ins>
</code></pre></blockquote>


<h3><a name="atomics.types">29.5 Atomic Types [atomics.types]</a></h3>

<p>
This section has the bulk of changes,
removing the named types in favor of only providing the productive type syntax.
The approach is to remove the sections on integral types and address types,
and turn the subsection on generic types to the section on types.
</p>

<h3><a name="atomics.types.integral">29.5.1 Integral Types [atomics.types.integral]</a></h3>

<p>
Remove this section.
</p>

<h3><a name="atomics.types.address">29.5.2 Address Type [atomics.types.address]</a></h3>

<p>
Remove this section.
</p>

<h3><a name="atomics.types.generic">29.5.3 Generic Type [atomics.types.generic]</a></h3>

<p>
Rename this subsection to 29.5 Atomic Types [atomics.types].
</p>

<p>
Edit the synopsis for the integral type specializations as follows.
</p>

<blockquote><pre><code>
template &lt;&gt; struct atomic&lt;<var>integral</var>&gt; <del>: atomic_<var>itype</var></del> {

<ins>    bool is_lock_free() const volatile;
    bool is_lock_free() const;
    void store(<var>integral</var>, memory_order = memory_order_seq_cst) volatile;
    void store(<var>integral</var>, memory_order = memory_order_seq_cst);
    <var>integral</var> load(memory_order = memory_order_seq_cst) const volatile;
    <var>integral</var> load(memory_order = memory_order_seq_cst) const;</ins>
    operator <var>integral</var>() const volatile;
    operator <var>integral</var>() const;
<ins>    <var>integral</var> exchange(<var>integral</var>,
                      memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> exchange(<var>integral</var>,
                      memory_order = memory_order_seq_cst);
    bool compare_exchange_weak(<var>integral</var>&amp;, <var>integral</var>,
                               memory_order, memory_order) volatile;
    bool compare_exchange_weak(<var>integral</var>&amp;, <var>integral</var>,
                               memory_order, memory_order);
    bool compare_exchange_strong(<var>integral</var>&amp;, <var>integral</var>,
                                 memory_order, memory_order) volatile;
    bool compare_exchange_strong(<var>integral</var>&amp;, <var>integral</var>,
                                 memory_order, memory_order);
    bool compare_exchange_weak(<var>integral</var>&amp;, <var>integral</var>,
                               memory_order = memory_order_seq_cst) volatile;
    bool compare_exchange_weak(<var>integral</var>&amp;, <var>integral</var>,
                               memory_order = memory_order_seq_cst);
    bool compare_exchange_strong(<var>integral</var>&amp;, <var>integral</var>,
                                 memory_order = memory_order_seq_cst) volatile;
    bool compare_exchange_strong(<var>integral</var>&amp;, <var>integral</var>,
                                 memory_order = memory_order_seq_cst);
    <var>integral</var> fetch_add(<var>integral</var>,
                       memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> fetch_add(<var>integral</var>,
                       memory_order = memory_order_seq_cst);
    <var>integral</var> fetch_sub(<var>integral</var>,
                       memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> fetch_sub(<var>integral</var>,
                       memory_order = memory_order_seq_cst);
    <var>integral</var> fetch_and(<var>integral</var>,
                       memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> fetch_and(<var>integral</var>,
                       memory_order = memory_order_seq_cst);
    <var>integral</var> fetch_or(<var>integral</var>,
                       memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> fetch_or(<var>integral</var>,
                       memory_order = memory_order_seq_cst);
    <var>integral</var> fetch_xor(<var>integral</var>,
                       memory_order = memory_order_seq_cst) volatile;
    <var>integral</var> fetch_xor(<var>integral</var>,
                       memory_order = memory_order_seq_cst);</ins>

    atomic() = default;
    constexpr atomic(<var>integral</var>);
    atomic(const atomic&amp;) = delete;
    atomic&amp; operator=(const atomic&amp;) = delete;
    atomic&amp; operator=(const atomic&amp;) volatile = delete;
    <var>integral</var> operator=(<var>integral</var>) volatile;
    <var>integral</var> operator=(<var>integral</var>);

<ins>    <var>integral</var> operator++(int) volatile;
    <var>integral</var> operator++(int);
    <var>integral</var> operator--(int) volatile;
    <var>integral</var> operator--(int);
    <var>integral</var> operator++() volatile;
    <var>integral</var> operator++();
    <var>integral</var> operator--() volatile;
    <var>integral</var> operator--();
    <var>integral</var> operator+=(<var>integral</var>) volatile;
    <var>integral</var> operator+=(<var>integral</var>);
    <var>integral</var> operator-=(<var>integral</var>) volatile;
    <var>integral</var> operator-=(<var>integral</var>);
    <var>integral</var> operator&amp;=(<var>integral</var>) volatile;
    <var>integral</var> operator&amp;=(<var>integral</var>);
    <var>integral</var> operator|=(<var>integral</var>) volatile;
    <var>integral</var> operator|=(<var>integral</var>);
    <var>integral</var> operator^=(<var>integral</var>) volatile;
    <var>integral</var> operator^=(<var>integral</var>);</ins>
};
</code></pre></blockquote>

<p>
Edit the synopsis for the pointer type specializations as follows.
</p>

<blockquote><pre><code>
template &lt;class T&gt; struct atomic&lt;T*&gt; <del>: atomic_address</del> {

<ins>    bool is_lock_free() const volatile;
    bool is_lock_free() const;</ins></ins>
    void store(T*, memory_order = memory_order_seq_cst) volatile;
    void store(T*, memory_order = memory_order_seq_cst);
    T* load(memory_order = memory_order_seq_cst) const volatile;
    T* load(memory_order = memory_order_seq_cst) const;
    operator T*() const volatile;
    operator T*() const;
    T* exchange(T*, memory_order = memory_order_seq_cst) volatile;
    T* exchange(T*, memory_order = memory_order_seq_cst);
    bool compare_exchange_weak(T*&amp;, T*,
                               memory_order, memory_order) volatile;
    bool compare_exchange_weak(T*&amp;, T*,
                               memory_order, memory_order);
    bool compare_exchange_strong(T*&amp;, T*,
                                 memory_order, memory_order) volatile;
    bool compare_exchange_strong(T*&amp;, T*,
                                 memory_order, memory_order);
    bool compare_exchange_weak(T*&amp;, T*,
                               memory_order = memory_order_seq_cst) volatile;
    bool compare_exchange_weak(T*&amp;, T*,
                               memory_order = memory_order_seq_cst);
    bool compare_exchange_strong(T*&amp;, T*,
                                 memory_order = memory_order_seq_cst) volatile;
    bool compare_exchange_strong(T*&amp;, T*,
                                 memory_order = memory_order_seq_cst);
    T* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst) volatile;
    T* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst);
    T* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst) volatile;
    T* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst);
    
    atomic() = default;
    constexpr atomic(T*);
    atomic(const atomic&amp;) = delete;
    atomic&amp; operator=(const atomic&amp;) = delete;
    atomic&amp; operator=(const atomic&amp;) volatile = delete;

    T* operator=(T*) volatile;
    T* operator=(T*);
    T* operator++(int) volatile;
    T* operator++(int);
    T* operator--(int) volatile;
    T* operator--(int);
    T* operator++() volatile;
    T* operator++();
    T* operator--() volatile;
    T* operator--();
    T* operator+=(ptrdiff_t) volatile;
    T* operator+=(ptrdiff_t);
    T* operator-=(ptrdiff_t) volatile;
    T* operator-=(ptrdiff_t);
};
</code></pre></blockquote>

<p>
After paragraph 1, add a new paragraph.
</p>

<blockquote>
The semantics of the operations on <code>atomic</code> specializations
are defined in 29.6.
</blockquote>

<p>
Edit paragraph 3 as follows.
</p>

<blockquote>
There are full specializations over the integral types
<ins>
(<code>char</code>,
<code>signed char</code>,
<code>unsigned char</code>,
<code>short</code>,
<code>unsigned short</code>,
<code>int</code>,
<code>unsigned int</code>,
<code>long</code>,
<code>unsigned long</code>,
<code>long long</code>,
<code>unsigned long long</code>,
<code>char16_t</code>,
<code>char32_t</code>,
<code>wchar_t</code>,
and any other types need by <code>&lt;cstdint&gt;</code> typedefs.)
</ins>
on the atomic class template.
For each integral type <var>integral</var>
<del>in the second column of Table 142 or Table 143</del>,
the specialization <code>atomic&lt;integral&gt;</code>
<del>shall be publicly derived from the corresponding atomic integral type
in the first column of the table.
In addition, the specialization <code>atomic&lt;bool&gt;</code>
shall be publicly derived from <code>atomic_bool</code>.</del>
<ins>provide additional atomic operations appropriate to integral types.</ins>
<del>These specializations
shall have trivial default constructors and trivial destructors.</del>
<ins>The atomic integral specializations
shall have standard layout.
They shall each have a trivial default constructor, and a trivial destructor.
They shall each support aggregate initialization syntax.
</ins>
</blockquote>

<p>
Insert a new paragraph after the one above.
</p>

<blockquote>
<ins>The specialization <code>atomic&lt;bool&gt;</code>
shall have standard layout.
It shall have a trivial default constructor and a trivial destructor.
It shall support aggregate initialization syntax.
</ins>
</blockquote>

<p>
Edit paragraph 4 as follows.
</p>

<blockquote>
There are pointer partial specializations
on the <code>atomic</code> class template.
<del>These specializations shall be publicly derived from atomic_address.</del>
The unit of addition/subtraction for these specializations
shall be the size of the referenced type.
These specializations
shall have trivial default constructors and trivial destructors.
</blockquote>

<p>
Insert a new paragraph after the one above.
</p>

<blockquote>
[<i>Note:</i>
The representation of atomic specializations
need not have the same size as their corresponding argument types.
They should have the same size whenever possible,
as it eases effort required to port existing code.
&mdash;<i>end note</i>]
</blockquote>

<h3><a name="atomics.types.operations">29.6 Operations on Atomic Types [atomics.types.operations]</a></h3>

<p>
The free functions in this section become templates or specializations thereof.
Technically, this would require adding a template name signature.
However, that change seems likely to be more confusing than helpful.
So, I have not suggested that change,
leaving it to the editor for the final decision.
</p>

<p>
Edit paragraph 1 as follows.
</p>

<blockquote>
There are only a few kinds of operations on atomic types,
though there are many instances on those kinds.
This section specifies each general kind.
The specific instances are defined in
<ins>29.2</ins> <del>29.5.1, 29.5.2,</del>
and <del>29.5.3</del> <ins>29.5</ins>.
</blockquote>

<p>
Edit paragraph 5 as follows.
</p>

<blockquote>
<p>
<i>Remarks:</i>
A macro that expands to a token sequence
suitable for <del>initializing</del> <ins>constant initialization of</ins>
an atomic variable <ins>of static storage duration</ins>
of a type that is
<del>initializion-compatible</del>
<ins>initialization-compatible</ins> with value.
<ins>
[<i>Note:</i>
This operation may need to initialize locks.
&mdash;<i>end note</i>]
</ins>
Concurrent access to the variable being initialized,
even via an atomic operation,
constitutes a data race.
[<i>Example:</i>
</p>
<blockquote><pre><code>
<del>atomic_int</del> <ins>atomic&lt;int&gt;</ins> v = ATOMIC_VAR_INIT(5);
</code></pre></blockquote>
<p>
&mdash;<i>end example</i>]
</p>
</blockquote>

<p>
Edit paragraph paragraph 7 as follows.
</p>

<blockquote>
<p>
<i>Effects:</i>
Dynamically initializes an atomic variable.
<del>Non-atomically</del>
<ins>That is, non-atomically</ins>
assigns the value desired to <code>*object</code>.
<ins>
[<i>Note:</i>
This operation may need to initialize locks.
&mdash;<i>end note</i>]
</ins>
Concurrent access from another thread,
even via an atomic operation, constitutes a data race.
</p>
</blockquote>

<h3><a name="atomics.compatibility">29.9 C Compatibility [atomics.compatibility]</a></h3>

<p>
Add a new section on C compatibility.
</p>

<p>
Add a new paragraph as follows.
<strong>Note:
Whether or not member operators
are defined when including <code>&lt;stdatomic.h&gt;</code>
was left open by the concurrency subcommittee.
This wording presupposes they are defined.</strong>
</p>

<blockquote>
<p>
Including the header <code>&lt;stdatomic.h&gt;</code>
will place the symbols of this clause
into the global namespace.
</p>
</blockquote>

<p>
Add a new paragraph as follows.
<strong>Note:
this issue was left open by the concurrency subcommittee.</strong>
<strong>Note:
The C committee may change the name of the macro
or remove its applicability to atomics.</strong>
</p>

<blockquote>
<p>
Implementations that define the macro <code>__STDC_NO_THREADS__</code>
need not provide the headers
<code>&lt;atomic&gt;</code> and
<code>&lt;stdatomic.h&gt;</code>
nor support any of their facilities.
</p>
</blockquote>

<p>
Add a new paragraph as follows.
</p>

<blockquote>
<p>
The header <code>&lt;stdatomic.h&gt;</code>
defines a macro <code>_Atomic</code>
as follows.
</p>
<blockquote><pre><code>
#define _Atomic(T) atomic&lt;T&gt;
<code></pre></blockquote>
</blockquote>

</body>
</html>
