std::atomic_flag (3) - Linux Manuals
std::atomic_flag: std::atomic_flag
NAME
std::atomic_flag - std::atomic_flag
Synopsis
Defined in header <atomic>
class atomic_flag; (since C++11)
std::atomic_flag is an atomic boolean type. Unlike all specializations of std::atomic, it is guaranteed to be lock-free. Unlike std::atomic<bool>, std::atomic_flag does not provide load or store operations.
Member functions
constructor (public member function)
operator= (public member function)
clear (public member function)
test_and_set (public member function)
Example
A spinlock mutex can be implemented in userspace using an atomic_flag
// Run this code
Output:
See also
atomic_flag_test_and_set
atomic_flag_test_and_set_explicit atomically sets the flag to true and returns its previous value
(C++11)
(C++11)
atomic_flag_clear
atomic_flag_clear_explicit atomically sets the value of the flag to false
(C++11)
(C++11)
ATOMIC_FLAG_INIT initializes an std::atomic_flag to false