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 指定。

異常安全

無異常保證: 絕不丟擲異常。

另見