When class B
is used as a static local variable in class A
constructor, does c++11 will make sure func()
be initialized only once in a thread-safe manner? Are the codes commented out redundant?
void func() {}
class B {
B() {
//static std::atomic<char> first_call(1);
//if (first_call.fetch_and((char)0)) {
func();
//}
}
};
class A {
A(){
static B;
}
};