[stdatomic.h.syn]

# 32 Concurrency support library [[thread]](./#thread)

## 32.5 Atomic operations [[atomics]](atomics#stdatomic.h.syn)

### 32.5.12 C compatibility [stdatomic.h.syn]

The header <stdatomic.h> provides the following definitions:

template<class T>using *std-atomic* = std::atomic<T>; // *exposition only*#define _Atomic(T) *std-atomic*<T>#define ATOMIC_BOOL_LOCK_FREE *see below*#define ATOMIC_CHAR_LOCK_FREE *see below*#define ATOMIC_CHAR16_T_LOCK_FREE *see below*#define ATOMIC_CHAR32_T_LOCK_FREE *see below*#define ATOMIC_WCHAR_T_LOCK_FREE *see below*#define ATOMIC_SHORT_LOCK_FREE *see below*#define ATOMIC_INT_LOCK_FREE *see below*#define ATOMIC_LONG_LOCK_FREE *see below*#define ATOMIC_LLONG_LOCK_FREE *see below*#define ATOMIC_POINTER_LOCK_FREE *see below*using std::[memory_order](depr.atomics.order#lib:memory_order "D.23.5 memory_­order​::​consume [depr.atomics.order]"); // *see below*using std::[memory_order_relaxed](#lib:memory_order_relaxed "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[memory_order_consume](#lib:memory_order_consume "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[memory_order_acquire](#lib:memory_order_acquire "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[memory_order_release](#lib:memory_order_release "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[memory_order_acq_rel](#lib:memory_order_acq_rel "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[memory_order_seq_cst](#lib:memory_order_seq_cst "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_flag](#lib:atomic_flag "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_bool](#lib:atomic_bool "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_char](#lib:atomic_char "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_schar](#lib:atomic_schar "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uchar](#lib:atomic_uchar "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_short](#lib:atomic_short "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_ushort](#lib:atomic_ushort "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int](#lib:atomic_int "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint](#lib:atomic_uint "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_long](#lib:atomic_long "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_ulong](#lib:atomic_ulong "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_llong](#lib:atomic_llong "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_ullong](#lib:atomic_ullong "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_char8_t](#lib:atomic_char8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_char16_t](#lib:atomic_char16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_char32_t](#lib:atomic_char32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_wchar_t](#lib:atomic_wchar_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int8_t](#lib:atomic_int8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint8_t](#lib:atomic_uint8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int16_t](#lib:atomic_int16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint16_t](#lib:atomic_uint16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int32_t](#lib:atomic_int32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint32_t](#lib:atomic_uint32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int64_t](#lib:atomic_int64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint64_t](#lib:atomic_uint64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_least8_t](#lib:atomic_int_least8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_least8_t](#lib:atomic_uint_least8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_least16_t](#lib:atomic_int_least16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_least16_t](#lib:atomic_uint_least16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_least32_t](#lib:atomic_int_least32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_least32_t](#lib:atomic_uint_least32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_least64_t](#lib:atomic_int_least64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_least64_t](#lib:atomic_uint_least64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_fast8_t](#lib:atomic_int_fast8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_fast8_t](#lib:atomic_uint_fast8_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_fast16_t](#lib:atomic_int_fast16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_fast16_t](#lib:atomic_uint_fast16_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_fast32_t](#lib:atomic_int_fast32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_fast32_t](#lib:atomic_uint_fast32_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_int_fast64_t](#lib:atomic_int_fast64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uint_fast64_t](#lib:atomic_uint_fast64_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_intptr_t](#lib:atomic_intptr_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uintptr_t](#lib:atomic_uintptr_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_size_t](#lib:atomic_size_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_ptrdiff_t](#lib:atomic_ptrdiff_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_intmax_t](#lib:atomic_intmax_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_uintmax_t](#lib:atomic_uintmax_t "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_is_lock_free](#lib:atomic_is_lock_free "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_load](#lib:atomic_load "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_load_explicit](#lib:atomic_load_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_store](#lib:atomic_store "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_store_explicit](#lib:atomic_store_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_exchange](#lib:atomic_exchange "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_exchange_explicit](#lib:atomic_exchange_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_compare_exchange_strong](#lib:atomic_compare_exchange_strong "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_compare_exchange_strong_explicit](#lib:atomic_compare_exchange_strong_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_compare_exchange_weak](#lib:atomic_compare_exchange_weak "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_compare_exchange_weak_explicit](#lib:atomic_compare_exchange_weak_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_add](#lib:atomic_fetch_add "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_add_explicit](#lib:atomic_fetch_add_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_sub](#lib:atomic_fetch_sub "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_sub_explicit](#lib:atomic_fetch_sub_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_and](#lib:atomic_fetch_and "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_and_explicit](#lib:atomic_fetch_and_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_or](#lib:atomic_fetch_or "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_or_explicit](#lib:atomic_fetch_or_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_xor](#lib:atomic_fetch_xor "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_fetch_xor_explicit](#lib:atomic_fetch_xor_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_flag_test_and_set](#lib:atomic_flag_test_and_set "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_flag_test_and_set_explicit](#lib:atomic_flag_test_and_set_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_flag_clear](#lib:atomic_flag_clear "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_flag_clear_explicit](#lib:atomic_flag_clear_explicit "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*#define ATOMIC_FLAG_INIT *see below*using std::[atomic_thread_fence](#lib:atomic_thread_fence "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*using std::[atomic_signal_fence](#lib:atomic_signal_fence "32.5.12 C compatibility [stdatomic.h.syn]"); // *see below*

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L7217)

Each [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]") for some name A in the synopsis above
makes available the same entity as std​::​A declared in [<atomic>](atomics.syn#header:%3catomic%3e "32.5.2 Header <atomic> synopsis [atomics.syn]")[.](#1.sentence-1)

Each macro listed above other than _Atomic(T) is defined as in [<atomic>](atomics.syn#header:%3catomic%3e "32.5.2 Header <atomic> synopsis [atomics.syn]")[.](#1.sentence-2)

It is unspecified whether [<stdatomic.h>](#header:%3cstdatomic.h%3e "32.5.12 C compatibility [stdatomic.h.syn]") makes available
any declarations in namespace std[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L7226)

Each of the [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]")*s* forintN_t, uintN_t, intptr_t, and uintptr_t listed above is defined if and only if the implementation defines
the corresponding [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") in [[atomics.syn]](atomics.syn "32.5.2 Header <atomic> synopsis")[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L7232)

Neither the _Atomic macro,
nor any of the non-macro global namespace declarations,
are provided by any C++ standard library header
other than [<stdatomic.h>](#header:%3cstdatomic.h%3e "32.5.12 C compatibility [stdatomic.h.syn]")[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L7238)

*Recommended practice*: Implementations should ensure
that C and C++ representations of atomic objects are compatible,
so that the same object can be accessed as both an _Atomic(T) from C code and an atomic<T> from C++ code[.](#4.sentence-1)

The representations should be the same, and
the mechanisms used to ensure atomicity and memory ordering
should be compatible[.](#4.sentence-2)
