C11 (and similar C++11) has a new primitive type in its new toolbox for atomics: atomic_flag
. As you’d perhaps imagine from the name, a variable of that type has two different states, called “cleared” and “set”, and access to it is atomic. It is even guaranteed to be “lock-free”, see below.
Sounds like atomic_flag
is the same as _Atomic(_Bool)
, doesn’t it? Not quite. Access to it is even more restricted than for a _Bool
, however it might be more efficient.