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-=.
返回值
调用前的存储值。
T 是 atomic 的模板参数(包含值的类型)。
数据竞争
无数据竞争(原子操作)。内存顺序由参数 sync 指定。