In addition to the atomic class, there are also a number of template-based functions defined in the <atomic> header which we can use in a manner more akin to the compiler's built-in atomic functions:
|
Function |
Description |
|
atomic_is_lock_free |
Checks whether the atomic type's operations are lock-free. |
|
atomic_storeatomic_store_explicit |
Atomically replaces the value of the atomic object with a non-atomic argument. |
|
atomic_load atomic_load_explicit |
Atomically obtains the value stored in an atomic object. |
|
atomic_exchange atomic_exchange_explicit |
Atomically replaces the value of the atomic object with a non-atomic argument and returns the old value of atomic. |
|
atomic_compare_exchange_weak atomic_compare_exchange_weak_explicit atomic_compare_exchange_strong atomic_compare_exchange_strong_explicit |
Atomically compares the value of the atomic object with a non-atomic argument and performs an atomic exchange if equal or atomic load if not. |
|
atomic_fetch_add atomic_fetch_add_explicit |
Adds a non-atomic value to an atomic object and obtains the previous value of atomic. |
|
atomic_fetch_sub atomic_fetch_sub_explicit |
Subtracts a non-atomic value from an atomic object and obtains the previous value of atomic. |
|
atomic_fetch_and atomic_fetch_and_explicit |
Replaces the atomic object with the result of logical AND with a non-atomic argument and obtains the previous value of the atomic. |
|
atomic_fetch_or atomic_fetch_or_explicit |
Replaces the atomic object with the result of logical OR with a non-atomic argument and obtains the previous value of atomic. |
|
atomic_fetch_xor atomic_fetch_xor_explicit |
Replaces the atomic object with the result of logical XOR with a non-atomic argument and obtains the previous value of atomic. |
|
atomic_flag_test_and_set atomic_flag_test_and_set_explicit |
Atomically sets the flag to true and returns its previous value. |
|
atomic_flag_clear atomic_flag_clear_explicit |
Atomically sets the value of the flag to false. |
|
atomic_init |
Non-atomic initialization of a default-constructed atomic object. |
|
kill_dependency |
Removes the specified object from the std::memory_order_consume dependency tree. |
|
atomic_thread_fence |
Generic memory order-dependent fence synchronization primitive. |
|
atomic_signal_fence |
Fence between a thread and a signal handler executed in the same thread. |
The difference between the regular and explicit functions is that the latter allows one to actually set the memory order to use. The former always uses memory_order_seq_cst as the memory order.