出版魔法静态线程安全吗?

NoS*_*tAl 5 static thread-safety c++11

想象一下,我有这个:

const string& get_name()
{
static auto* ptr_name=new string("Ron");
return *ptr_name;
}
Run Code Online (Sandbox Code Playgroud)

如果多个线程正在调用get_name是否是UB?

How*_*ant 4

这在 C++11 及更高版本中是线程安全的。

VS-2013 尚未实现 C++11 的这一部分。VS-14 的作用:

http://blogs.msdn.com/b/vcblog/archive/2014/06/11/c-11-14-feature-tables-for-visual-studio-14-ctp1.aspx