function
<atomic>

std::atomic_flag_test_and_set

bool atomic_flag_test_and_set (volatile atomic_flag* obj) noexcept;
bool atomic_flag_test_and_set (atomic_flag* obj) noexcept;
Test and set atomic flag
Sets the atomic flag pointed by obj and returns the value it had immediately before the call.

The entire operation is atomic (an atomic read-modify-write operation): the value of obj is not affected by other threads between the instant its value is read (to be returned) and the moment it is modified by this function.

See atomic_flag::test_and_set for the equivalent member function of atomic_flag.

Parameters

obj
Pointer to the atomic_flag object to set.

Return value

true if obj was already set before the call.
false otherwise.

Data races

No data races (atomic operation). The operation uses sequential consistency (memory_order_seq_cst).

Exception safety

No-throw guarantee: never throws exceptions.

See also