我怎么知道C ++编译器是否制作了线程安全的静态对象代码?

时间:2017-06-12 13:01:07

标签: c++ multithreading c++11 gcc visual-c++

在GCC中,除非给出__cxa_guard_acquire编译器选项,否则本地静态变量是线程安全的(通过特殊函数-fno-threadsafe-statics)。

同样,MSVC 2015及更高版本支持相同功能,可以/Zc:threadSafeInit-禁用。

是否有任何宏或其他功能,如__EXCEPTIONS__GXX_RTTI来检查编译阶段是否启用了这些功能?我认为检查__cplusplus_MSC_VER不会有帮助。

1 个答案:

答案 0 :(得分:2)

看起来有一个定义__cpp_threadsafe_static_init

  

SD-6: SG10 Feature Test Recommendations

     

C ++ 11功能

     

C ++ 11的重要功能

     

文件。编号标题主要部分宏名称值标题

     

N2660 动态初始化和销毁​​并发3.6 __cpp_threadsafe_static_init 200806 预定义

CLang - http://clang.llvm.org/cxx_status.html#tsgithub.com

GCC - https://gcc.gnu.org/projects/cxx-status.html

MSVC - 正在调查的功能请求https://developercommunity.visualstudio.com/content/problem/96337/feature-request-cpp-threadsafe-static-init.html

在cppreference.com上有用: