June 2018
Intermediate to advanced
348 pages
8h 45m
English
std::atomic_flag represents a Boolean flag, and it is the simplest among all the atomic types in the standard library. This is the only type where all operations on it are required to be lock-free in every platform. This type is very basic, hence it is intended as a building block only.
A std::atomic_flag object must always be initialized with ATOMIC_FLAG_INIT to set the state to clear:
std::atomic_flag flg = ATOMIC_FLAG_INIT;
This is the only atomic type that requires such initialization, irrespective of the scope of its declaration. Once it is initialized, there are only three operations permissible with this type: destroy it, clear it, or set a query for the previous value. These correspond to the destructor, the clear() ...