T atomic_fetch_add(volatilestd::atomic<T>*obj, typenamestd::atomic<T>::difference_typearg)noexcept; (2)(since C++11) template<classT> T atomic_fetch_add_explicit(std::atomic<T>*obj, typenamestd::atomic<T>::difference_typearg,
#include <iostream> #include <thread> #include <atomic> std::atomic<long long> data; void do_work() { data.fetch_add(1, std::memory_order_relaxed); } int main() { std::thread th1(do_work); std::thread th2(do_work); std::thread th3(do_work); std::thread th4(do_work); ...
T fetch_add( T arg, std::memory_order order = std::memory_order_seq_cst ) noexcept; T fetch_add( T arg, std::memory_order order = std::memory_order_seq_cst ) volatile noexcept; 仅为atomic<T*> 模板特化的成员 (2) T* fetch_add( std::ptrdiff_t arg, std::memory_order or...
T fetch_add( T arg, std::memory_order order = std::memory_order_seq_cst ) volatile; (2) (since C++11) (member only of atomic<T*> template specialization) T* fetch_add( std::ptrdiff_t arg, std::memory_order order = std::memory_order_seq_cst ); ...
std::atomic::operators (int) std::atomic::store std::atomic_compare_exchange_strong std::atomic_compare_exchange_strong_explicit std::atomic_compare_exchange_weak std::atomic_compare_exchange_weak_explicit std::atomic_exchange std::atomic_exchange_explicit std::atomic_fetch_add std::atomic_fetch...
T fetch_add(T arg,std::memory_orderorder= std::memory_order_seq_cst)volatilenoexcept; (2)(since C++11) member only ofatomic<T*>partial specialization T*fetch_add(std::ptrdiff_targ, std::memory_orderorder= std::memory_order_seq_cst)noexcept; ...
对所有指针类型的部分特化std::atomic。这些特化具有标准布局,平凡的默认构造函数,并支持适用于指针类型的原子算术操作,如fetch_add,fetch_sub。 对std::shared_ptr和std::weak_ptr的部分特化std::atomic>和std::atomic>。 对于整型类型的特化: 当与以下整型类型之一实例化时,std::atomic提供适用于整型类型的额外...
T atomic_fetch_sub( volatile std::atomic<T>* obj, typename std::atomic<T>::difference_type arg ) noexcept; (2) template< class T > T atomic_fetch_sub_explicit( std::atomic<T>* obj, typename std::atomic<T>::difference_type arg, std::memory_order order ) noexcept; template<...
res = std::atomic_compare_exchange_strong_explicit(&a0, &expected, desired, std::memory_order_relaxed, std::memory_order_relaxed); assert(res && expected == 3 && desired == 2 && a0 == 2); a0 = 1; val = std::atomic_fetch_add(&a0, 2); ...
atomic_exchange_explicit<>() (std::shared_ptr) (C++11 起)(C++20 中弃用)atomic_fetch_add<>() (C++11 起)atomic_fetch_add_explicit<>() (C++11 起)atomic_fetch_and<>() (C++11 起)atomic_fetch_and_explicit<>() (C++11 起)atomic_fetch_or<>() (C++11 起)atomic_fetch_or_explicit<>...