ATOMIC_FLAG_INIT

Defined in header <atomic>
1
#define ATOMIC_FLAG_INIT /* implementation-defined */

Defines the expression which can be used to initialize std::atomic_flag to clear (false) state with the statement std::atomic_flag v = ATOMIC_FLAG_INIT;. It is unspecified if it can be used with other initialization contexts.

If the flag has static storage duration, this initialization is static.

This is the only way to initialize std::atomic_flag to a definite value: the value held after any other initialization is unspecified.

Example

1
2
3
4
5
6
7
8
9
10
#include <atomic>
  
std::atomic_flag static_flag = ATOMIC_FLAG_INIT; // static initialization,
// guaranteed to be available during dynamic initialization of static objects.
  
int main()
{
    std::atomic_flag automatic_flag = ATOMIC_FLAG_INIT; // guaranteed to work
//    std::atomic_flag another_flag(ATOMIC_FLAG_INIT); // unspecified
}

See also

(C++11)
the lock-free boolean atomic type
(class)
doc_CPP
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.