Skip to content

LWG Poll 8: P0943R6 Support C atomics in C++ #4372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 139 additions & 1 deletion source/atomics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
\ref{atomics.types.generic} & Class template \tcode{atomic} & \\
\ref{atomics.nonmembers} & Non-member functions & \\
\ref{atomics.flag} & Flag type and operations & \\
\ref{atomics.fences} & Fences & \\
\ref{atomics.fences} & Fences & \\ \rowsep
\ref{stdatomic.h.syn} & C compatibility & \tcode{<stdatomic.h>} \\
\end{libsumtab}

\rSec1[atomics.syn]{Header \tcode{<atomic>} synopsis}
Expand Down Expand Up @@ -3702,3 +3703,140 @@
that \tcode{atomic_thread_fence} would have inserted are not emitted.
\end{note}
\end{itemdescr}

\rSec1[stdatomic.h.syn]{C compatibility}

The header \libheaderdef{stdatomic.h} provides the following definitions:

\begin{codeblock}
template<class T>
using @\exposid{std-atomic}@ = std::atomic<T>; // exposition only

#define _Atomic(T) @\exposid{std-atomic}@<T>

#define ATOMIC_BOOL_LOCK_FREE @\seebelow@
#define ATOMIC_CHAR_LOCK_FREE @\seebelow@
#define ATOMIC_CHAR16_T_LOCK_FREE @\seebelow@
#define ATOMIC_CHAR32_T_LOCK_FREE @\seebelow@
#define ATOMIC_WCHAR_T_LOCK_FREE @\seebelow@
#define ATOMIC_SHORT_LOCK_FREE @\seebelow@
#define ATOMIC_INT_LOCK_FREE @\seebelow@
#define ATOMIC_LONG_LOCK_FREE @\seebelow@
#define ATOMIC_LLONG_LOCK_FREE @\seebelow@
#define ATOMIC_POINTER_LOCK_FREE @\seebelow@

using std::@\libglobal{memory_order}@ // \seebelow
using std::@\libglobal{memory_order_relaxed}@ // \seebelow
using std::@\libglobal{memory_order_consume}@ // \seebelow
using std::@\libglobal{memory_order_acquire}@ // \seebelow
using std::@\libglobal{memory_order_release}@ // \seebelow
using std::@\libglobal{memory_order_acq_rel}@ // \seebelow
using std::@\libglobal{memory_order_seq_cst}@ // \seebelow

using std::@\libglobal{atomic_flag}@ // \seebelow

using std::@\libglobal{atomic_bool}@ // \seebelow
using std::@\libglobal{atomic_char}@ // \seebelow
using std::@\libglobal{atomic_schar}@ // \seebelow
using std::@\libglobal{atomic_uchar}@ // \seebelow
using std::@\libglobal{atomic_short}@ // \seebelow
using std::@\libglobal{atomic_ushort}@ // \seebelow
using std::@\libglobal{atomic_int}@ // \seebelow
using std::@\libglobal{atomic_uint}@ // \seebelow
using std::@\libglobal{atomic_long}@ // \seebelow
using std::@\libglobal{atomic_ulong}@ // \seebelow
using std::@\libglobal{atomic_llong}@ // \seebelow
using std::@\libglobal{atomic_ullong}@ // \seebelow
using std::@\libglobal{atomic_char8_t}@ // \seebelow
using std::@\libglobal{atomic_char16_t}@ // \seebelow
using std::@\libglobal{atomic_char32_t}@ // \seebelow
using std::@\libglobal{atomic_wchar_t}@ // \seebelow
using std::@\libglobal{atomic_int8_t}@ // \seebelow
using std::@\libglobal{atomic_uint8_t}@ // \seebelow
using std::@\libglobal{atomic_int16_t}@ // \seebelow
using std::@\libglobal{atomic_uint16_t}@ // \seebelow
using std::@\libglobal{atomic_int32_t}@ // \seebelow
using std::@\libglobal{atomic_uint32_t}@ // \seebelow
using std::@\libglobal{atomic_int64_t}@ // \seebelow
using std::@\libglobal{atomic_uint64_t}@ // \seebelow
using std::@\libglobal{atomic_int_least8_t}@ // \seebelow
using std::@\libglobal{atomic_uint_least8_t}@ // \seebelow
using std::@\libglobal{atomic_int_least16_t}@ // \seebelow
using std::@\libglobal{atomic_uint_least16_t}@ // \seebelow
using std::@\libglobal{atomic_int_least32_t}@ // \seebelow
using std::@\libglobal{atomic_uint_least32_t}@ // \seebelow
using std::@\libglobal{atomic_int_least64_t}@ // \seebelow
using std::@\libglobal{atomic_uint_least64_t}@ // \seebelow
using std::@\libglobal{atomic_int_fast8_t}@ // \seebelow
using std::@\libglobal{atomic_uint_fast8_t}@ // \seebelow
using std::@\libglobal{atomic_int_fast16_t}@ // \seebelow
using std::@\libglobal{atomic_uint_fast16_t}@ // \seebelow
using std::@\libglobal{atomic_int_fast32_t}@ // \seebelow
using std::@\libglobal{atomic_uint_fast32_t}@ // \seebelow
using std::@\libglobal{atomic_int_fast64_t}@ // \seebelow
using std::@\libglobal{atomic_uint_fast64_t}@ // \seebelow
using std::@\libglobal{atomic_intptr_t}@ // \seebelow
using std::@\libglobal{atomic_uintptr_t}@ // \seebelow
using std::@\libglobal{atomic_size_t}@ // \seebelow
using std::@\libglobal{atomic_ptrdiff_t}@ // \seebelow
using std::@\libglobal{atomic_intmax_t}@ // \seebelow
using std::@\libglobal{atomic_uintmax_t}@ // \seebelow

using std::@\libglobal{atomic_is_lock_free}@ // \seebelow
using std::@\libglobal{atomic_load}@ // \seebelow
using std::@\libglobal{atomic_load_explicit}@ // \seebelow
using std::@\libglobal{atomic_store}@ // \seebelow
using std::@\libglobal{atomic_store_explicit}@ // \seebelow
using std::@\libglobal{atomic_exchange}@ // \seebelow
using std::@\libglobal{atomic_exchange_explicit}@ // \seebelow
using std::@\libglobal{atomic_compare_exchange_strong}@ // \seebelow
using std::@\libglobal{atomic_compare_exchange_strong_explicit}@ // \seebelow
using std::@\libglobal{atomic_compare_exchange_weak}@ // \seebelow
using std::@\libglobal{atomic_compare_exchange_weak_explicit}@ // \seebelow
using std::@\libglobal{atomic_fetch_add}@ // \seebelow
using std::@\libglobal{atomic_fetch_add_explicit}@ // \seebelow
using std::@\libglobal{atomic_fetch_sub}@ // \seebelow
using std::@\libglobal{atomic_fetch_sub_explicit}@ // \seebelow
using std::@\libglobal{atomic_fetch_or}@ // \seebelow
using std::@\libglobal{atomic_fetch_or_explicit}@ // \seebelow
using std::@\libglobal{atomic_fetch_and}@ // \seebelow
using std::@\libglobal{atomic_fetch_and_explicit}@ // \seebelow
using std::@\libglobal{atomic_flag_test_and_set}@ // \seebelow
using std::@\libglobal{atomic_flag_test_and_set_explicit}@ // \seebelow
using std::@\libglobal{atomic_flag_clear}@ // \seebelow
using std::@\libglobal{atomic_flag_clear_explicit}@ // \seebelow

using std::@\libglobal{atomic_thread_fence}@ // \seebelow
using std::@\libglobal{atomic_signal_fence}@ // \seebelow
\end{codeblock}

\pnum
Each \grammarterm{using-declaration} for some name $A$ in the synopsis above
makes available the same entity as \tcode{std::$A$}
declared in \libheaderrefx{atomic}{atomics.syn}.
Each macro listed above other than \tcode{_Atomic(T)}
is defined as in \libheader{atomic}.
It is unspecified whether \libheader{stdatomic.h} makes available
any declarations in namespace \tcode{std}.

\pnum
Each of the \grammarterm{using-declaration}s for
\tcode{int$N$_t}, \tcode{uint$N$_t}, \tcode{intptr_t}, and \tcode{uintptr_t}
listed above is defined if and only if the implementation defines
the corresponding typedef name in \ref{atomics.syn}.

\pnum
Neither the \tcode{_Atomic} macro,
nor any of the non-macro global namespace declarations,
are provided by any \Cpp{} standard library header
other than \libheader{stdatomic.h}.

\pnum
\recommended
Implementations should ensure
that C and \Cpp{} representations of atomic objects are compatible,
so that the same object can be accessed as both an \tcode{_Atomic(T)}
from C code and an \tcode{atomic<T>} from \Cpp{} code.
The representations should be the same, and
the mechanisms used to ensure atomicity and memory ordering
should be compatible.
4 changes: 1 addition & 3 deletions source/compatibility.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2674,9 +2674,7 @@

\pnum
There are no \Cpp{} headers for the C standard library's headers
\libnoheader{stdatomic.h},
\libnoheader{stdnoreturn.h},
and \libnoheader{threads.h},
\libnoheader{stdnoreturn.h} and \libnoheader{threads.h},
nor are these headers from the C standard library headers themselves part of \Cpp{}.

\pnum
Expand Down
6 changes: 4 additions & 2 deletions source/future.tex
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,18 @@
\libheaderdef{signal.h} \\
\libheader{stdalign.h} \\
\libheaderdef{stdarg.h} \\
\libheader{stdatomic.h} \\
\libheader{stdbool.h} \\
\libheaderdef{stddef.h} \\
\libheaderdef{stdint.h} \\
\columnbreak
\libheaderdef{stdint.h} \\
\libheaderdef{stdio.h} \\
\libheaderdef{stdlib.h} \\
\libheaderdef{string.h} \\
\libheader{tgmath.h} \\
\libheaderdef{time.h} \\
\libheaderdef{uchar.h} \\
\columnbreak
\libheaderdef{uchar.h} \\
\libheaderdef{wchar.h} \\
\libheaderdef{wctype.h} \\
\end{multicolfloattable}
Expand Down Expand Up @@ -365,6 +366,7 @@
\libdeprheaderref{complex.h},
\libdeprheaderref{iso646.h},
\libdeprheaderref{stdalign.h},\newline
\libheaderref{stdatomic.h},
\libdeprheaderref{stdbool.h}, and
\libdeprheaderref{tgmath.h},
each of
Expand Down
1 change: 0 additions & 1 deletion source/lib-intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@
\begin{footnote}
It is intentional that there is no \Cpp{} header
for any of these C headers:
\libnoheader{stdatomic.h},
\libnoheader{stdnoreturn.h},
\libnoheader{threads.h}.
\end{footnote}
Expand Down
1 change: 1 addition & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@
#define @\defnlibxname{cpp_lib_ssize}@ 201902L // also in \libheader{iterator}
#define @\defnlibxname{cpp_lib_stacktrace}@ 202011L // also in \libheader{stacktrace}
#define @\defnlibxname{cpp_lib_starts_ends_with}@ 201711L // also in \libheader{string}, \libheader{string_view}
#define @\defnlibxname{cpp_lib_stdatomic_h}@ 202011L // also in \libheader{stdatomic.h}
#define @\defnlibxname{cpp_lib_string_contains}@ 202011L // also in \libheader{string}, \libheader{string_view}
#define @\defnlibxname{cpp_lib_string_udls}@ 201304L // also in \libheader{string}
#define @\defnlibxname{cpp_lib_string_view}@ 201803L // also in \libheader{string}, \libheader{string_view}
Expand Down