我怎么知道C++编译器是否制作线程安全的静态对象代码
How can I know if C++ compiler make thread-safe static object code?
在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++编译器支持
相关文章:
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 返回从字符串文本创建的静态string_view是否安全?
- 当我在C++中调用 struce 的只读静态成员时,线程是否安全
- C++:用IIFE线程初始化静态局部变量安全吗
- 确保静态布尔检查的线程安全
- 为什么静态向下转换unique_ptr不安全?
- 从内部使用静态 std::string 的函数返回 const char * 是否安全?
- VC++6 线程安全静态初始化
- 静态类数据成员的线程安全
- 我怎么知道C++编译器是否制作线程安全的静态对象代码
- 将对象(如 STL 对象)传入和传出静态库是否安全
- 为什么静态局部变量的 MSVC 线程安全初始化使用 TLS
- 静态指针指向会员数组的安全操作员[]访问
- C++多线程:是本地静态lambda线程安全的初始化
- 使用函数模板中静态局部变量的地址作为类型标识符是否安全
- 有没有更好的方法可以使此代码线程安全?线程局部静态似乎是一个生硬的工具
- GCC 的 TSAN 报告了线程安全静态本地的数据争用
- 如何在 C++11 中的函数内初始化线程安全静态常量向量
- 多个线程调用exit()时的安全静态析构函数
- 功能与安全/静态与动态实例化