Namespaces
Variants

std:: atomic_fetch_xor, std:: atomic_fetch_xor_explicit

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
atomic_fetch_xor atomic_fetch_xor_explicit
(C++11) (C++11)
Free functions for atomic flags
定义于头文件 <atomic>
template < class T >

T atomic_fetch_xor ( std:: atomic < T > * obj,

typename std:: atomic < T > :: value_type arg ) noexcept ;
(1) (C++11 起)
template < class T >

T atomic_fetch_xor ( volatile std:: atomic < T > * obj,

typename std:: atomic < T > :: value_type arg ) noexcept ;
(2) (C++11 起)
template < class T >

T atomic_fetch_xor_explicit ( std:: atomic < T > * obj,
typename std:: atomic < T > :: value_type arg,

std:: memory_order order ) noexcept ;
(3) (C++11 起)
template < class T >

T atomic_fetch_xor_explicit ( volatile std:: atomic < T > * obj,
typename std:: atomic < T > :: value_type arg,

std:: memory_order order ) noexcept ;
(4) (C++11 起)

原子地将 obj 所指向的值替换为 obj 原值与 arg 的按位异或结果。返回 obj 先前持有的值。

该操作的执行过程如下所示:

1,2) obj - > fetch_xor ( arg )
3,4) obj - > fetch_xor ( arg, order )

如果 std::atomic<T> 没有 fetch_xor 成员(该成员仅适用于 整型类型 ,不包括 bool ),则程序非良构。

目录

参数

obj - 指向要修改的原子对象的指针
arg - 要与原子对象中存储的值进行按位异或运算的值
order - 内存同步排序方式

返回值

* obj 修改顺序 中,紧邻此函数生效前的值。

示例

缺陷报告

下列行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 适用范围 发布时的行为 正确行为
P0558R1 C++11 由于
T 是从多个参数推导得出,因此需要精确类型匹配
T 仅从
obj 推导

参见

原子地在参数和原子对象的值之间执行按位异或操作,并获取先前持有的值
( std::atomic<T> 的公开成员函数)
用非原子参数的按位或结果替换原子对象,并获取该原子对象的先前值
(函数模板)
用非原子参数的按位与结果替换原子对象,并获取该原子对象的先前值
(函数模板)
C 文档 for atomic_fetch_xor , atomic_fetch_xor_explicit