Atomics
Overview
The _Atomic(...) specifier is used to declare an atomic object. Operations on atomic objects are synchronized across threads. Additionally, if the atomic type is lock-free, then the corresponding operations are uninterruptible.
_Atomic cannot be applied to array types.
Test-and-set
The atomic_flag type, found in <stdatomic.h>, provides the test-and-set functionality. It should be initialized to the clear state by assigning to macro ATOMIC_FLAG_INIT.
Lock-Free Property
The lock-free property of a C type indicates that no locking occurs internally. As a result, operations on objects of the type are uninterruptible. This property can be checked for _Atomic(T) via macro ATOMIC_<T>_LOCK_FREE. Values are interpreted as:
0indicates the type is never lock-free.1indicates the type is sometimes lock-free.2indicates the type is always lock-free.