Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is atomic_flag_test_and_set_explicit in C?

Hassaan Waqar

The atomic_flag_test_and_set_explicit function is defined in the <stdatomic.h> header file in C.

It takes in two parameters:

  1. a volatile atomic_flag object
  2. 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_flag is an atomic boolean type variable that is guaranteed to be lock-free. It is used to provide synchronization within threads in programs.

order refers to the memory synchronization ordering for the operation

The illustration below shows how atomic_flag_test_and_set works:

How does atomic_flag_test_and_set_explicit work?


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 );


Theatomic_flag_test_and_set_explicit function takes in two parameters:

  1. an object of type volatile atomic flag*
  2. an order of type memory_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_explicit function defined in C++. Therefore, relevant code in C no longer exists.




Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring