Namespaces
Variants

std:: atomic_fetch_max, std:: atomic_fetch_max_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_max atomic_fetch_max_explicit
(C++26) (C++26)
Free functions for atomic flags
定义于头文件 <atomic>
template < class T >

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

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

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

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

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

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

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

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

以原子方式将 obj 所指向的值替换为 obj 旧值与 arg 之间执行 std::max 的结果。返回 obj 先前持有的值。该操作的执行方式相当于以下代码:

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

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

目录

参数

obj - 指向待修改原子对象的指针
arg - 将与原子对象中存储的值进行 std::max 运算的值
order - 内存同步排序方式

返回值

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

注释

功能测试 标准 功能
__cpp_lib_atomic_min_max 202403L (C++26) 原子最小值/最大值

示例

参见

(C++26)
以原子方式执行参数与原子对象值之间的 std::max 并获取先前持有的值
( std::atomic<T> 的公开成员函数)
将原子对象替换为与非常量参数进行 std::min 的结果并获取原子的先前值
(函数模板)