Pio*_*trK 5 c++ multithreading c++11
我还是C++ 11 thread_local存储的新手.特别是我对以下代码感到好奇:
class foo_t
{
foo_t() { std::cout << "Foo ctor"; }
~foo_t() { std::cout << "Foo dtor"; }
}
thread_local foo_t foo;
void bar() { }
void baz() { }
int main()
{
std::thread t1(bar), t2(baz);
t1.join(); t2.join();
}
Run Code Online (Sandbox Code Playgroud)
foo_t在这个例子中,ctor/dtor是否会被调用两次(我的意思是标准是否需要这样做)?如果我搬到bar其他翻译单位怎么办?如果这样的单位没有声明foo_t也foo怎么办?