What is the safe way to initialize std::atomic_flag in a class constructor?
This question seems to ask the same question I am asking - moreover, here it asks a complaint about a problem with the compiler.
My question relates to the C ++ standard itself. According to this site, the initialization syntax of the constructor initializer std::atomic_flag not specified.
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 }
Is this information correct? If so, I assume that:
struct Foo { Foo() : flag(ATOMIC_FLAG_INIT) { } std::atomic_flag flag; };
... also not specified. So, does this mean that we cannot use std::atomic_flag as a member variable of a class? Or is it safe if we just call std::atomic_flag::clear() from the class constructor?
c ++ c ++ 11
Siler
source share