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

How can I know if C++ compiler make thread-safe static object code?

本文关键字:安全 静态 对象 代码 线程 C++ 编译器 是否 我怎么知道      更新时间:2023-10-16

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

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

是否有任何宏或其他功能(如__EXCEPTIONS__GXX_RTTI(在编译阶段检查这些功能是否已启用?我认为检查__cplusplus_MSC_VER无济于事。

看起来有一个定义__cpp_threadsafe_static_init .

SD-6:第10研究组功能测试建议:

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 上有用:

  • 功能测试建议
  • C++编译器支持