public member function
<atomic>

std::atomic::fetch_sub

如果 T 是整数类型 (1)
T fetch_sub (T val, memory_order sync = memory_order_seq_cst) volatile noexcept;T fetch_sub (T val, memory_order sync = memory_order_seq_cst) noexcept;
如果 T 是指针类型 (2)
T fetch_sub (ptrdiff_t val, memory_order sync = memory_order_seq_cst) volatile noexcept;T fetch_sub (ptrdiff_t val, memory_order sync = memory_order_seq_cst) noexcept;
Subtract from contained value
Subtracts val from the contained value and returns the value it had immediately before the operation.

整个操作是原子的(一个原子读-修改-写操作):在函数读取(并返回)其值到修改其值的时刻之间,该值不会受到其他线程的影响。

This member function is only defined in the atomic specializations for integral (1) and pointer (2) types (except for bool).

If the default value is used for the second argument, this function is equivalent to atomic::operator-=.

参数

val
Value to subtract.
Tatomic 的模板参数(包含值的类型)。
ptrdiff_t 是一个有符号整数类型。
sync
操作的同步模式。
这应该是 memory_order enum 类型的值之一。

返回值

调用前的存储值。
Tatomic 的模板参数(包含值的类型)。

数据竞争

无数据竞争(原子操作)。内存顺序由参数 sync 指定。

异常安全

无异常保证: 绝不抛出异常。

另见