std::atomic_flag_test_and_set,std::atomic_flag_test_and_set_explicit (3) - Linux Manuals
std::atomic_flag_test_and_set,std::atomic_flag_test_and_set_explicit: std::atomic_flag_test_and_set,std::atomic_flag_test_and_set_explicit
NAME
std::atomic_flag_test_and_set,std::atomic_flag_test_and_set_explicit - std::atomic_flag_test_and_set,std::atomic_flag_test_and_set_explicit
Synopsis
Defined in header <atomic>
bool atomic_flag_test_and_set( volatile std::atomic_flag* p ) noexcept;
bool atomic_flag_test_and_set( std::atomic_flag* p ) noexcept;
bool atomic_flag_test_and_set_explicit( volatile std::atomic_flag* p, (1) (since C++11)
std::memory_order order ) noexcept; (2) (since C++11)
bool atomic_flag_test_and_set_explicit( std::atomic_flag* p,
std::memory_order order ) noexcept;
Atomically changes the state of a std::atomic_flag pointed to by p to set (true) and returns the value it held before.
Parameters
p - pointer to std::atomic_flag to access
order - the memory synchronization order for this operation
Return value
The value previously held by the flag pointed to by p
Possible implementation
First version
Second version
Third version
Fourth version
Example
A spinlock mutex can be implemented in userspace using an atomic_flag
// Run this code
Output:
See also
atomic_flag the lock-free boolean atomic type