Search code examples
c++multithreadingatomic

std::atomic_flag initialization result


Is is really necessery to initialize std::atomic_flag in this way:

std::atomic_flag flag = ATOMIC_FLAG_INIT;

In my opinion it should have same result:

std::atomic_flag flag;
flag.clear();

I have read all about this class from cppreference, but I am still not sure.


Solution

  • According to ATOMIC_FLAG_INIT spec:

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