Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What is atomic_flag_test_and_set in C?

Hassaan Waqar

The atomic_flag_test_and_set function is defined in the <stdatomic.h> header file in C. It takes in a single parameter: a volatile atomic_flag object. 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.

The illustration below shows how atomic_flag_test_and_set works:

How does atomic_flag_test_and_set work?


The atomic_flag_test_and_set function is defined as follows:

bool atomic_flag_test_and_set( volatile atomic_flag* obj );


Theatomic_flag_test_and_set function takes in a single value of type volatile atomic flag*.

Return value

The atomic_flag_test_and_set function returns a boolean value which indicates the state of the flag. The value can be either true or false.

The atomic_flag_test_and_set is outdated and has been replaced by the atomic_flag_test_and_set_explicit function. Therefore, relevant code for atomic_flag_test_and_set function does not exist.




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

View all Courses

Keep Exploring