An operation on an atomic variable is safe to a
limited degree from race conditions caused by multiple
threads attempting to update the same variable.
Modifications to atomic variables must be done through a
limited set of generic functions and macros declared by
. In their
declarations, atomic-type matches any atomic
type. non-atomic-type matches the
corresponding non-atomic type. atomic-modifying-type is the
same, except when dealing with atomic pointer types, in which case,
it is ptrdiff_t
.
#include
void atomic_store(volatile atomic-type *obj,
non-atomic-type value);
void atomic_store_explicit(volatile atomic-type *obj,
non-atomic-type value,
memory_order order);
#include
non-atomic-type atomic_load(volatile atomic-type *obj);
non-atomic-type atomic_load_explicit(volatile atomic-type *obj,
memory_order order);
#include
non-atomic-type atomic_exchange(volatile atomic-type *obj,
non-atomic-type value);
non-atomic-type atomic_exchange_explicit(volatile atomic-type *obj,
non-atomic-type value,
memory_order order);
#include
_Bool
atomic_compare_exchange_strong(volatile atomic-type *obj,
non-atomic-type *expect,
non-atomic-type value);
_Bool
atomic_compare_exchange_strong_explicit(volatile atomic-type *obj,
non-atomic-type *expect,
non-atomic-type value,
memory_order success,
memory_order failure);
_Bool
atomic_compare_exchange_weak(volatile atomic-type *obj,
non-atomic-type *expect,
non-atomic-type value);
_Bool
atomic_compare_exchange_weak_explicit(volatile atomic-type *obj,
non-atomic-type *expect,
non-atomic-type value,
memory_order success,
memory_order failure);
#include
non-atomic-type atomic_fetch_add(volatile atomic-type *obj,
atomic-modifying-type value);
non-atomic-type atomic_fetch_sub(volatile atomic-type *obj,
atomic-modifying-type value);
non-atomic-type atomic_fetch_or(volatile atomic-type *obj,
atomic-modifying-type value);
non-atomic-type atomic_fetch_xor(volatile atomic-type *obj,
atomic-modifying-type value);
non-atomic-type atomic_fetch_and(volatile atomic-type *obj,
atomic-modifying-type value);
#include
_Bool
atomic_flag_test_and_set(volatile atomic_flag *obj);
_Bool
atomic_flag_test_and_set_explicit(volatile atomic_flag *obj,
memory_order order);
#include
void atomic_flag_clear(volatile atomic_flag *obj);
void atomic_flag_clear_explicit(volatile atomic_flag *obj,
memory_order order);