What is atomic_flag_test_and_set_explicit in C?
The atomic_flag_test_and_set_explicit function is defined in the <stdatomic.h> header file in C.
It takes in two parameters:
- a
volatile atomic_flagobject - an order of type
memory_order.
The function returns the value of the atomic_flag pointed to by the obj and then sets the current value to true.
atomic_flagis anatomic booleantype variable that is guaranteed to be lock-free. It is used to provide synchronization within threads in programs.
orderrefers to the memory synchronization ordering for the operation
The illustration below shows how atomic_flag_test_and_set works:
Declaration
The atomic_flag_test_and_set_explicit function is defined as follows:
bool atomic_flag_test_and_set_explicit( volatile atomic_flag* obj, memory_order order );
Parameter
Theatomic_flag_test_and_set_explicit function takes in two parameters:
- an
objectof typevolatile atomic flag* - an
orderof typememory_order
Return value
The atomic_flag_test_and_set_explicit function returns a boolean value which indicates the state of the flag. The value can be either true or false.
Modern operating systems have an updated implementation of
atomic_flag_test_and_set_explicitfunction defined inC++. Therefore, relevant code inCno longer exists.
Free Resources