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

Byo*_*Lee 5 c++ multithreading gcc visual-c++ c++11

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

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

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

Mih*_*ayl 3

看起来好像有一个定义__cpp_threadsafe_static_init

SD-6:SG10 功能测试建议

C++11 特性

C++11 的显着特性

博士。编号 标题 主要部分 宏名称 值 标题

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

CLang - http://clang.llvm.org/cxx_status.html#ts ( github.com )

海湾合作委员会- 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 上有用: