标准库头文件 <atomic>

来自cppreference.com
< cpp‎ | header
 
 
 

此头文件是原子操作库的一部分。

(C++11)
atomic 类模板及其针对布尔、整型和指针类型的特化
(类模板)
提供非原子对象上的原子操作
(类模板)
免锁的布尔原子类型
(类)
为给定的原子操作定义内存顺序制约
(枚举)

typedef

std::atomic_bool std::atomic<bool>
std::atomic_char std::atomic<char>
std::atomic_schar std::atomic<signed char>
std::atomic_uchar std::atomic<unsigned char>
std::atomic_short std::atomic<short>
std::atomic_ushort std::atomic<unsigned short>
std::atomic_int std::atomic<int>
std::atomic_uint std::atomic<unsigned int>
std::atomic_long std::atomic<long>
std::atomic_ulong std::atomic<unsigned long>
std::atomic_llong std::atomic<long long>
std::atomic_ullong std::atomic<unsigned long long>
std::atomic_char16_t std::atomic<char16_t>
std::atomic_char32_t std::atomic<char32_t>
std::atomic_wchar_t std::atomic<wchar_t>
std::atomic_int8_t std::atomic<std::int8_t>
std::atomic_uint8_t std::atomic<std::uint8_t>
std::atomic_int16_t std::atomic<std::int16_t>
std::atomic_uint16_t std::atomic<std::uint16_t>
std::atomic_int32_t std::atomic<std::int32_t>
std::atomic_uint32_t std::atomic<std::uint32_t>
std::atomic_int64_t std::atomic<std::int64_t>
std::atomic_uint64_t std::atomic<std::uint64_t>
std::atomic_int_least8_t std::atomic<int_least8_t>
std::atomic_uint_least8_t std::atomic<uint_least8_t>
std::atomic_int_least16_t std::atomic<int_least16_t>
std::atomic_uint_least16_t std::atomic<uint_least16_t>
std::atomic_int_least32_t std::atomic<int_least32_t>
std::atomic_uint_least32_t std::atomic<uint_least32_t>
std::atomic_int_least64_t std::atomic<int_least64_t>
std::atomic_uint_least64_t std::atomic<uint_least64_t>
std::atomic_int_fast8_t std::atomic<int_fast8_t>
std::atomic_uint_fast8_t std::atomic<uint_fast8_t>
std::atomic_int_fast16_t std::atomic<int_fast16_t>
std::atomic_uint_fast16_t std::atomic<uint_fast16_t>
std::atomic_int_fast32_t std::atomic<int_fast32_t>
std::atomic_uint_fast32_t std::atomic<uint_fast32_t>
std::atomic_int_fast64_t std::atomic<int_fast64_t>
std::atomic_uint_fast64_t std::atomic<uint_fast64_t>
std::atomic_intptr_t std::atomic<intptr_t>
std::atomic_uintptr_t std::atomic<uintptr_t>
std::atomic_size_t std::atomic<size_t>
std::atomic_ptrdiff_t std::atomic<ptrdiff_t>
std::atomic_intmax_t std::atomic<intmax_t>
std::atomic_uintmax_t std::atomic<uintmax_t>

函数

检查对该原子类型的操作是否是无锁的
(函数模板)
原子地以非原子实参替换原子对象的值
(函数模板)
原子地获得存储于原子对象的值
(函数模板)
原子地以非原子实参的值替换原子对象的值,并返回该原子对象的旧值
(函数模板)
原子地比较原子对象和非原子实参的值,若相等则进行 atomic_exchange,若不相等则进行 atomic_load
(函数模板)
将非原子值加到原子对象,并获得原子对象的先前值
(函数模板)
从原子对象减去非原子值,并获得原子对象的先前值
(函数模板)
将原子对象替换为与非原子实参逻辑与的结果,并获得原子对象的先前值
(函数模板)
将原子对象替换为与非原子实参逻辑或的结果,并获得原子对象的先前值
(函数模板)
将原子对象替换为与非原子实参逻辑异或的结果,并获得原子对象的先前值
(函数模板)
原子地设置标志为 true 并返回其先前值
(函数)
原子地设置标志值为 false
(函数)
对默认构造的原子对象进行非原子初始化
(函数模板)
std::memory_order_consume 依赖树移除指定对象
(函数模板)
通用的依赖内存顺序的栅栏同步原语
(函数)
线程与执行于同一线程的信号处理函数间的栅栏
(函数)

预处理器宏

静态存储期的原子对象的常量初始化
(宏函数)
std::atomic_flag 初始化为 false
(宏常量)

概要

namespace std {
 
    /* C++17 前:
 
    typedef enum memory_order {
        memory_order_relaxed,
        memory_order_consume,
        memory_order_acquire,
        memory_order_release,
        memory_order_acq_rel,
        memory_order_seq_cst
    } memory_order;
 
    */
 
    enum class memory_order : /* 未指明 */ {
        relaxed, consume, acquire, release, acq_rel, seq_cst
    };
 
    inline constexpr memory_order memory_order_relaxed = memory_order::relaxed;
    inline constexpr memory_order memory_order_consume = memory_order::consume;
    inline constexpr memory_order memory_order_acquire = memory_order::acquire;
    inline constexpr memory_order memory_order_release = memory_order::release;
    inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel;
    inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst;
 
    template <class T>
    T kill_dependency(T y) noexcept;
 
    // 免锁属性
    #define ATOMIC_BOOL_LOCK_FREE /* 未指明 */
    #define ATOMIC_CHAR_LOCK_FREE /* 未指明 */
    #define ATOMIC_CHAR16_T_LOCK_FREE /* 未指明 */
    #define ATOMIC_CHAR32_T_LOCK_FREE /* 未指明 */
    #define ATOMIC_WCHAR_T_LOCK_FREE /* 未指明 */
    #define ATOMIC_SHORT_LOCK_FREE /* 未指明 */
    #define ATOMIC_INT_LOCK_FREE /* 未指明 */
    #define ATOMIC_LONG_LOCK_FREE /* 未指明 */
    #define ATOMIC_LLONG_LOCK_FREE /* 未指明 */
    #define ATOMIC_POINTER_LOCK_FREE /* 未指明 */
 
    // 类模板 atomic_ref
    template<class T> struct atomic_ref;
    // 对指针的部分特化
    template<class T> struct atomic_ref<T*>;
 
    // 通用原子类型
    template<class T> struct atomic;
    // 对指针的部分特化
    template<class T> struct atomic<T*>;
 
    // 具名 typedef
    using atomic_bool           = atomic<bool>;
    using atomic_char           = atomic<char>;
    using atomic_schar          = atomic<signed char>;
    using atomic_uchar          = atomic<unsigned char>;
    using atomic_short          = atomic<short>;
    using atomic_ushort         = atomic<unsigned short>;
    using atomic_int            = atomic<int>;
    using atomic_uint           = atomic<unsigned int>;
    using atomic_long           = atomic<long>;
    using atomic_ulong          = atomic<unsigned long>;
    using atomic_llong          = atomic<long long>;
    using atomic_ullong         = atomic<unsigned long long>;
    using atomic_char16_t       = atomic<char16_t>;
    using atomic_char32_t       = atomic<char32_t>;
    using atomic_wchar_t        = atomic<wchar_t>;
 
    using atomic_int8_t         = atomic<int8_t>;
    using atomic_uint8_t        = atomic<uint8_t>;
    using atomic_int16_t        = atomic<int16_t>;
    using atomic_uint16_t       = atomic<uint16_t>;
    using atomic_int32_t        = atomic<int32_t>;
    using atomic_uint32_t       = atomic<uint32_t>;
    using atomic_int64_t        = atomic<int64_t>;
    using atomic_uint64_t       = atomic<uint64_t>;
 
    using atomic_int_least8_t   = atomic<int_least8_t>;
    using atomic_uint_least8_t  = atomic<uint_least8_t>;
    using atomic_int_least16_t  = atomic<int_least16_t>;
    using atomic_uint_least16_t = atomic<uint_least16_t>;
    using atomic_int_least32_t  = atomic<int_least32_t>;
    using atomic_uint_least32_t = atomic<uint_least32_t>;
    using atomic_int_least64_t  = atomic<int_least64_t>;
    using atomic_uint_least64_t = atomic<uint_least64_t>;
 
    using atomic_int_fast8_t    = atomic<int_fast8_t>;
    using atomic_uint_fast8_t   = atomic<uint_fast8_t>;
    using atomic_int_fast16_t   = atomic<int_fast16_t>;
    using atomic_uint_fast16_t  = atomic<uint_fast16_t>;
    using atomic_int_fast32_t   = atomic<int_fast32_t>;
    using atomic_uint_fast32_t  = atomic<uint_fast32_t>;
    using atomic_int_fast64_t   = atomic<int_fast64_t>;
    using atomic_uint_fast64_t  = atomic<uint_fast64_t>;
 
    using atomic_intptr_t       = atomic<intptr_t>;
    using atomic_uintptr_t      = atomic<uintptr_t>;
    using atomic_size_t         = atomic<size_t>;
    using atomic_ptrdiff_t      = atomic<ptrdiff_t>;
    using atomic_intmax_t       = atomic<intmax_t>;
    using atomic_uintmax_t      = atomic<uintmax_t>;
 
    // 非成员函数
    template<class T>
    bool atomic_is_lock_free(const volatile atomic<T>*) noexcept;
    template<class T>
    bool atomic_is_lock_free(const atomic<T>*) noexcept;
    template<class T>
    void atomic_init(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    void atomic_init(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    void atomic_store(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    void atomic_store(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    void atomic_store_explicit(volatile atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    void atomic_store_explicit(atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    T atomic_load(const volatile atomic<T>*) noexcept;
    template<class T>
    T atomic_load(const atomic<T>*) noexcept;
    template<class T>
    T atomic_load_explicit(const volatile atomic<T>*, memory_order) noexcept;
    template<class T>
    T atomic_load_explicit(const atomic<T>*, memory_order) noexcept;
    template<class T>
    T atomic_exchange(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_exchange(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_exchange_explicit(volatile atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    T atomic_exchange_explicit(atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    bool atomic_compare_exchange_weak(volatile atomic<T>*,
                                      typename atomic<T>::value_type*,
                                      typename atomic<T>::value_type) noexcept;
    template<class T>
    bool atomic_compare_exchange_weak(atomic<T>*,
                                      typename atomic<T>::value_type*,
                                      typename atomic<T>::value_type) noexcept;
    template<class T>
    bool atomic_compare_exchange_strong(volatile atomic<T>*,
                                        typename atomic<T>::value_type*,
                                        typename atomic<T>::value_type) noexcept;
    template<class T>
    bool atomic_compare_exchange_strong(atomic<T>*,
                                        typename atomic<T>::value_type*,
                                        typename atomic<T>::value_type) noexcept;
    template<class T>
    bool atomic_compare_exchange_weak_explicit(volatile atomic<T>*,
                                               typename atomic<T>::value_type*,
                                               typename atomic<T>::value_type,
                                               memory_order, memory_order) noexcept;
    template<class T>
    bool atomic_compare_exchange_weak_explicit(atomic<T>*,
                                               typename atomic<T>::value_type*,
                                               typename atomic<T>::value_type,
                                               memory_order, memory_order) noexcept;
    template<class T>
    bool atomic_compare_exchange_strong_explicit(volatile atomic<T>*,
                                                 typename atomic<T>::value_type*,
                                                 typename atomic<T>::value_type,
                                                 memory_order, memory_order) noexcept;
    template<class T>
    bool atomic_compare_exchange_strong_explicit(atomic<T>*,
                                                 typename atomic<T>::value_type*,
                                                 typename atomic<T>::value_type,
                                                 memory_order, memory_order) noexcept;
 
    template<class T>
    T atomic_fetch_add(volatile atomic<T>*, typename atomic<T>::difference_type) noexcept;
    template<class T>
    T atomic_fetch_add(atomic<T>*, typename atomic<T>::difference_type) noexcept;
    template<class T>
    T atomic_fetch_add_explicit(volatile atomic<T>*, typename atomic<T>::difference_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_add_explicit(atomic<T>*, typename atomic<T>::difference_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_sub(volatile atomic<T>*, typename atomic<T>::difference_type) noexcept;
    template<class T>
    T atomic_fetch_sub(atomic<T>*, typename atomic<T>::difference_type) noexcept;
    template<class T>
    T atomic_fetch_sub_explicit(volatile atomic<T>*, typename atomic<T>::difference_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_sub_explicit(atomic<T>*, typename atomic<T>::difference_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_and(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_and(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_and_explicit(volatile atomic<T>*, typename atomic<T>::value_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_and_explicit(atomic<T>*, typename atomic<T>::value_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_or(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_or(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_or_explicit(volatile atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    T atomic_fetch_or_explicit(atomic<T>*, typename atomic<T>::value_type,
                               memory_order) noexcept;
    template<class T>
    T atomic_fetch_xor(volatile atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_xor(atomic<T>*, typename atomic<T>::value_type) noexcept;
    template<class T>
    T atomic_fetch_xor_explicit(volatile atomic<T>*, typename atomic<T>::value_type,
                                memory_order) noexcept;
    template<class T>
    T atomic_fetch_xor_explicit(atomic<T>*, typename atomic<T>::value_type,
                                memory_order) noexcept;
 
    // 初始化
    #define ATOMIC_VAR_INIT(value) /*see description*/
 
    // 标志类型与操作
    struct atomic_flag;
 
    bool atomic_flag_test_and_set(volatile atomic_flag*) noexcept;
    bool atomic_flag_test_and_set(atomic_flag*) noexcept;
    bool atomic_flag_test_and_set_explicit(volatile atomic_flag*,
                                           memory_order) noexcept;
    bool atomic_flag_test_and_set_explicit(atomic_flag*, memory_order) noexcept;
    void atomic_flag_clear(volatile atomic_flag*) noexcept;
    void atomic_flag_clear(atomic_flag*) noexcept;
    void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order) noexcept;
    void atomic_flag_clear_explicit(atomic_flag*, memory_order) noexcept;
 
    #define ATOMIC_FLAG_INIT /* 见说明 */
 
    // 栅栏
    extern "C" void atomic_thread_fence(memory_order) noexcept;
    extern "C" void atomic_signal_fence(memory_order) noexcept;

std::atomic

template <class T> struct atomic {
    using value_type = T;
 
    bool is_lock_free() const volatile noexcept;
    bool is_lock_free() const noexcept;
    void store(T, memory_order = memory_order_seq_cst) volatile noexcept;
    void store(T, memory_order = memory_order_seq_cst) noexcept;
    T load(memory_order = memory_order_seq_cst) const volatile noexcept;
    T load(memory_order = memory_order_seq_cst) const noexcept;
    operator T() const volatile noexcept;
    operator T() const noexcept;
    T exchange(T, memory_order = memory_order_seq_cst) volatile noexcept;
    T exchange(T, memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order, memory_order) volatile noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order, memory_order) noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order, memory_order) volatile noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order, memory_order) noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order = memory_order_seq_cst) noexcept;
 
    atomic() noexcept = default;
    constexpr atomic(T) noexcept;
    atomic(const atomic&) = delete;
    atomic& operator=(const atomic&) = delete;
    atomic& operator=(const atomic&) volatile = delete;
    T operator=(T) volatile noexcept;
    T operator=(T) noexcept;
};

std::atomic 对整数类型的特化

template<> struct atomic</* 整型 */> {
    using value_type = /* 整型 */;
    using difference_type = value_type;
 
    bool is_lock_free() const volatile noexcept;
    bool is_lock_free() const noexcept;
    void store(/* 整型 */,
               memory_order = memory_order_seq_cst) volatile noexcept;
    void store(/* 整型 */,
               memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ load(memory_order = memory_order_seq_cst) const volatile noexcept;
    /* 整型 */ load(memory_order = memory_order_seq_cst) const noexcept;
    operator /* 整型 */() const volatile noexcept;
    operator /* 整型 */() const noexcept;
    /* 整型 */ exchange(/* 整型 */,
                          memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ exchange(/* 整型 */,
                          memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order, memory_order) volatile noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order, memory_order) noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order, memory_order) volatile noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order, memory_order) noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ fetch_add(/* 整型 */,
                           memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ fetch_add(/* 整型 */,
                           memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ fetch_sub(/* 整型 */,
                           memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ fetch_sub(/* 整型 */,
                           memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ fetch_and(/* 整型 */,
                           memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ fetch_and(/* 整型 */,
                           memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ fetch_or(/* 整型 */,
                          memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ fetch_or(/* 整型 */,
                          memory_order = memory_order_seq_cst) noexcept;
    /* 整型 */ fetch_xor(/* 整型 */,
                           memory_order = memory_order_seq_cst) volatile noexcept;
    /* 整型 */ fetch_xor(/* 整型 */,
                           memory_order = memory_order_seq_cst) noexcept;
 
    atomic() noexcept = default;
    constexpr atomic(/* 整型 */) noexcept;
    atomic(const atomic&) = delete;
    atomic& operator=(const atomic&) = delete;
    atomic& operator=(const atomic&) volatile = delete;
    /* 整型 */ operator=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator=(/* 整型 */) noexcept;
    /* 整型 */ operator++(int) volatile noexcept;
    /* 整型 */ operator++(int) noexcept;
    /* 整型 */ operator--(int) volatile noexcept;
    /* 整型 */ operator--(int) noexcept;
    /* 整型 */ operator++() volatile noexcept;
    /* 整型 */ operator++() noexcept;
    /* 整型 */ operator--() volatile noexcept;
    /* 整型 */ operator--() noexcept;
    /* 整型 */ operator+=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator+=(/* 整型 */) noexcept;
    /* 整型 */ operator-=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator-=(/* 整型 */) noexcept;
    /* 整型 */ operator&=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator&=(/* 整型 */) noexcept;
    /* 整型 */ operator|=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator|=(/* 整型 */) noexcept;
    /* 整型 */ operator^=(/* 整型 */) volatile noexcept;
    /* 整型 */ operator^=(/* 整型 */) noexcept;
};

std::atomic 对浮点类型的特化

template<> struct atomic</* 浮点 */> {
    using value_type = /* 浮点 */;
    using difference_type = value_type;
    static constexpr bool is_always_lock_free = /*implementation-defined*/;
    bool is_lock_free() const volatile noexcept;
    bool is_lock_free() const noexcept;
    void store(/* 浮点 */, memory_order = memory_order_seq_cst) volatile noexcept;
    void store(/* 浮点 */, memory_order = memory_order_seq_cst) noexcept;
    /* 浮点 */ load(memory_order = memory_order_seq_cst) volatile noexcept;
    /* 浮点 */ load(memory_order = memory_order_seq_cst) noexcept;
    operator /* 浮点 */() volatile noexcept;
    operator /* 浮点 */() noexcept;
    /* 浮点 */ exchange(/* 浮点 */,
                                memory_order = memory_order_seq_cst) volatile noexcept;
    /* 浮点 */ exchange(/* 浮点 */,
                                memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                                memory_order, memory_order) volatile noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                               memory_order, memory_order) noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order, memory_order) volatile noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order, memory_order) noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                               memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                               memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order = memory_order_seq_cst) noexcept;
 
    /* 浮点 */ fetch_add(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    /* 浮点 */ fetch_add(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) noexcept;
    /* 浮点 */ fetch_sub(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    /* 浮点 */ fetch_sub(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) noexcept;
 
    atomic() noexcept = default;
    constexpr atomic(/* 浮点 */) noexcept;
 
    atomic(const atomic&) = delete;
    atomic& operator=(const atomic&) = delete;
    atomic& operator=(const atomic&) volatile = delete;
    /* 浮点 */ operator=(/* 浮点 */) volatile noexcept;
    /* 浮点 */ operator=(/* 浮点 */) noexcept;
 
    /* 浮点 */ operator+=(/* 浮点 */) volatile noexcept;
    /* 浮点 */ operator+=(/* 浮点 */) noexcept;
    /* 浮点 */ operator-=(/* 浮点 */) volatile noexcept;
    /* 浮点 */ operator-=(/* 浮点 */) noexcept;
};

std::atomic 对指针类型的特化

template <class T> struct atomic<T*> {
    using value_type = T*;
    using difference_type = ptrdiff_t;
 
    bool is_lock_free() const volatile noexcept;
    bool is_lock_free() const noexcept;
    void store(T*, memory_order = memory_order_seq_cst) volatile noexcept;
    void store(T*, memory_order = memory_order_seq_cst) noexcept;
    T* load(memory_order = memory_order_seq_cst) const volatile noexcept;
    T* load(memory_order = memory_order_seq_cst) const noexcept;
    operator T*() const volatile noexcept;
    operator T*() const noexcept;
    T* exchange(T*, memory_order = memory_order_seq_cst) volatile noexcept;
    T* exchange(T*, memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_weak(T*&, T*, memory_order, memory_order) volatile noexcept;
    bool compare_exchange_weak(T*&, T*, memory_order, memory_order) noexcept;
    bool compare_exchange_strong(T*&, T*, memory_order, memory_order) volatile noexcept;
    bool compare_exchange_strong(T*&, T*, memory_order, memory_order) noexcept;
    bool compare_exchange_weak(T*&, T*,
                               memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_weak(T*&, T*,
                               memory_order = memory_order_seq_cst) noexcept;
    bool compare_exchange_strong(T*&, T*,
                                 memory_order = memory_order_seq_cst) volatile noexcept;
    bool compare_exchange_strong(T*&, T*,
                                 memory_order = memory_order_seq_cst) noexcept;
    T* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst) volatile noexcept;
    T* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst) noexcept;
    T* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst) volatile noexcept;
    T* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst) noexcept;
 
    atomic() noexcept = default;
    constexpr atomic(T*) noexcept;
    atomic(const atomic&) = delete;
    atomic& operator=(const atomic&) = delete;
    atomic& operator=(const atomic&) volatile = delete;
    T* operator=(T*) volatile noexcept;
    T* operator=(T*) noexcept;
    T* operator++(int) volatile noexcept;
    T* operator++(int) noexcept;
    T* operator--(int) volatile noexcept;
    T* operator--(int) noexcept;
    T* operator++() volatile noexcept;
    T* operator++() noexcept;
    T* operator--() volatile noexcept;
    T* operator--() noexcept;
    T* operator+=(ptrdiff_t) volatile noexcept;
    T* operator+=(ptrdiff_t) noexcept;
    T* operator-=(ptrdiff_t) volatile noexcept;
    T* operator-=(ptrdiff_t) noexcept;
};

std::atomic_ref

template<class T> struct atomic_ref {
private:
    T* ptr; // 仅用于阐释
public:
    using value_type = T;
    static constexpr bool is_always_lock_free = /* 由实现定义 */;
    static constexpr size_t required_alignment = /* 由实现定义 */;
 
    atomic_ref() = delete;
    atomic_ref& operator=(const atomic_ref&) = delete;
 
    explicit atomic_ref(T&);
    atomic_ref(const atomic_ref&) noexcept;
 
    T operator=(T) const noexcept;
    operator T() const noexcept;
 
    bool is_lock_free() const noexcept;
    void store(T, memory_order = memory_order_seq_cst) const noexcept;
    T load(memory_order = memory_order_seq_cst) const noexcept;
    T exchange(T, memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order, memory_order) const noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order, memory_order) const noexcept;
    bool compare_exchange_weak(T&, T,
                               memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_strong(T&, T,
                                 memory_order = memory_order_seq_cst) const noexcept;
};

std::atomic_ref 对整数类型的特化

template<> struct atomic_ref</* 整型 */> {
private:
    /* 整型 */* ptr; // 仅用于阐释
public:
    using value_type = /* 整型 */;
    using difference_type = value_type;
    static constexpr bool is_always_lock_free = /* 由实现定义 */;
    static constexpr size_t required_alignment = /* 由实现定义 */;
 
    atomic_ref() = delete;
    atomic_ref& operator=(const atomic_ref&) = delete;
 
    explicit atomic_ref(/* 整型 */&);
    atomic_ref(const atomic_ref&) noexcept;
 
    /* 整型 */ operator=(/* 整型 */) const noexcept;
    operator /* 整型 */() const noexcept;
 
    bool is_lock_free() const noexcept;
    void store(/* 整型 */, memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ load(memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ exchange(/* 整型 */,
                           memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order, memory_order) const noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order, memory_order) const noexcept;
    bool compare_exchange_weak(/* 整型 */&, /* 整型 */,
                               memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_strong(/* 整型 */&, /* 整型 */,
                                 memory_order = memory_order_seq_cst) const noexcept;
 
    /* 整型 */ fetch_add(/* 整型 */,
                           memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ fetch_sub(/* 整型 */,
                           memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ fetch_and(/* 整型 */,
                           memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ fetch_or(/* 整型 */,
                          memory_order = memory_order_seq_cst) const noexcept;
    /* 整型 */ fetch_xor(/* 整型 */,
                           memory_order = memory_order_seq_cst) const noexcept;
 
    /* 整型 */ operator++(int) const noexcept;
    /* 整型 */ operator--(int) const noexcept;
    /* 整型 */ operator++() const noexcept;
    /* 整型 */ operator--() const noexcept;
    /* 整型 */ operator+=(/* 整型 */) const noexcept;
    /* 整型 */ operator-=(/* 整型 */) const noexcept;
    /* 整型 */ operator&=(/* 整型 */) const noexcept;
    /* 整型 */ operator

std::atomic_ref 对浮点类型的特化

template<> struct atomic_ref</* 浮点 */> {
private:
    /* 浮点 */* ptr; // 仅用于阐释
public:
    using value_type = /* 浮点 */;
    using difference_type = value_type;
    static constexpr bool is_always_lock_free = /* 由实现定义 */;
    static constexpr size_t required_alignment = /* 由实现定义 */;
 
    atomic_ref() = delete;
    atomic_ref& operator=(const atomic_ref&) = delete;
 
    explicit atomic_ref(/* 浮点 */&);
    atomic_ref(const atomic_ref&) noexcept;
 
    /* 浮点 */ operator=(/* 浮点 */) noexcept;
    operator /* 浮点 */() const noexcept;
 
    bool is_lock_free() const noexcept;
    void store(/* 浮点 */, memory_order = memory_order_seq_cst) const noexcept;
    /* 浮点 */ load(memory_order = memory_order_seq_cst) const noexcept;
    /* 浮点 */ exchange(/* 浮点 */,
                                memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                               memory_order, memory_order) const noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order, memory_order) const noexcept;
    bool compare_exchange_weak(/* 浮点 */&, /* 浮点 */,
                               memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_strong(/* 浮点 */&, /* 浮点 */,
                                 memory_order = memory_order_seq_cst) const noexcept;
 
    /* 浮点 */ fetch_add(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) const noexcept;
    /* 浮点 */ fetch_sub(/* 浮点 */,
                                 memory_order = memory_order_seq_cst) const noexcept;
 
    /* 浮点 */ operator+=(/* 浮点 */) const noexcept;
    /* 浮点 */ operator-=(/* 浮点 */) const noexcept;
};

std::atomic_ref 对指针类型的特化

template<class T> struct atomic_ref<T*> {
private:
    T** ptr; // 仅用于阐释
public:
    using value_type = T*;
    using difference_type = ptrdiff_t;
    static constexpr bool is_always_lock_free = /* 由实现定义 */;
    static constexpr size_t required_alignment = /* 由实现定义 */;
 
    atomic_ref() = delete;
    atomic_ref& operator=(const atomic_ref&) = delete;
 
    explicit atomic_ref(T*&);
    atomic_ref(const atomic_ref&) noexcept;
 
    T* operator=(T*) const noexcept;
    operator T*() const noexcept;
 
    bool is_lock_free() const noexcept;
    void store(T*, memory_order = memory_order_seq_cst) const noexcept;
    T* load(memory_order = memory_order_seq_cst) const noexcept;
    T* exchange(T*, memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_weak(T*&, T*,
                               memory_order, memory_order) const noexcept;
    bool compare_exchange_strong(T*&, T*,
                                 memory_order, memory_order) const noexcept;
    bool compare_exchange_weak(T*&, T*,
                               memory_order = memory_order_seq_cst) const noexcept;
    bool compare_exchange_strong(T*&, T*,
                                 memory_order = memory_order_seq_cst) const noexcept;
 
    T* fetch_add(difference_type, memory_order = memory_order_seq_cst) const noexcept;
    T* fetch_sub(difference_type, memory_order = memory_order_seq_cst) const noexcept;
 
    T* operator++(int) const noexcept;
    T* operator--(int) const noexcept;
    T* operator++() const noexcept;
    T* operator--() const noexcept;
    T* operator+=(difference_type) const noexcept;
    T* operator-=(difference_type) const noexcept;
};

std::atomic_flag

typedef struct atomic_flag {
    bool test_and_set(memory_order = memory_order_seq_cst) volatile noexcept;
    bool test_and_set(memory_order = memory_order_seq_cst) noexcept;
    void clear(memory_order = memory_order_seq_cst) volatile noexcept;
    void clear(memory_order = memory_order_seq_cst) noexcept;
    atomic_flag() noexcept = default;
    atomic_flag(const atomic_flag&) = delete;
    atomic_flag& operator=(const atomic_flag&) = delete;
    atomic_flag& operator=(const atomic_flag&) volatile = delete;
} atomic_flag;