Namespaces
Variants

std::atomic<T>:: operator&=,|=,^=

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
仅属于 atomic< Integral  > 特化的成员
T operator & = ( T arg ) noexcept ;
(1) (自 C++11 起)
T operator & = ( T arg ) volatile noexcept ;
(2) (自 C++11 起)
T operator | = ( T arg ) noexcept ;
(3) (自 C++11 起)
T operator | = ( T arg ) volatile noexcept ;
(4) (自 C++11 起)
T operator ^ = ( T arg ) noexcept ;
(5) (自 C++11 起)
T operator ^ = ( T arg ) volatile noexcept ;
(6) (自 C++11 起)

以原子操作将当前值替换为先前值与 arg 参与计算的结果。该操作属于读-修改-写操作。

  • operator & = 执行原子按位与操作。等价于 return fetch_and ( arg ) & arg ;
  • operator | = 执行原子按位或操作。等价于 return fetch_or ( arg ) | arg ;
  • operator ^ = 执行原子按位异或操作。等价于 return fetch_xor ( arg ) ^ arg ;

std:: atomic < T > :: is_always_lock_free false 且任何 volatile 重载参与重载决议时,该用法被弃用。

(since C++20)

目录

参数

arg - 算术运算的参数

返回值

结果值(即对 * this 修改顺序 中对应成员函数生效前的值应用相应二元运算符所得的结果)。

注释

与大多数复合赋值运算符不同,原子类型的复合赋值运算符不会返回其左操作数的引用,而是返回存储值的副本。

参见

以原子方式执行参数与原子对象值的按位与操作,并获取先前持有的值
(公开成员函数)
以原子方式执行参数与原子对象值的按位或操作,并获取先前持有的值
(公开成员函数)
以原子方式执行参数与原子对象值的按位异或操作,并获取先前持有的值
(公开成员函数)
将原子值递增或递减一
(公开成员函数)
对原子值进行加法或减法运算
(公开成员函数)