我如何知道C ++编译器是否生成线程安全的静态对象代码? [英] How can I know if C++ compiler make thread-safe static object code?

查看:173
本文介绍了我如何知道C ++编译器是否生成线程安全的静态对象代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



同样,MSVC 2015及以后的版本支持相同的功能,可以通过 / Zc:threadSafeInit -

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

解决方案

看起来有一个定义 __ cpp_threadsafe_static_init


SD-6:SG10功能测试建议

C ++ 11特性



C ++ 11的重要特性 p>

Doc。编号标题主要部分宏名称值头



N2660 具有并发性的动态初始化和销毁​​3.6 __ cpp_threadsafe_static_init 200806 预定义


CLang - http://clang.llvm.org/cxx_status.html#ts github.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有用:




In GCC, local static variable is thread-safe (by special function__cxa_guard_acquire) unless -fno-threadsafe-statics compiler option is given.

Similarly, MSVC 2015 and onward version support the same feature and can be disabled by /Zc:threadSafeInit-.

Is there any macro or other features, like __EXCEPTIONS or __GXX_RTTI to check on compilation stage if such features are enabled or not? I think checking __cplusplus or _MSC_VER won't help.

解决方案

Looks like there is one define __cpp_threadsafe_static_init.

SD-6: SG10 Feature Test Recommendations:

C++11 features

Significant features of C++11

Doc. No. Title Primary Section Macro name Value Header

N2660 Dynamic Initialization and Destruction with Concurrency 3.6 __cpp_threadsafe_static_init 200806 predefined

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

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

MSVC - Feature request under investigation https://developercommunity.visualstudio.com/content/problem/96337/feature-request-cpp-threadsafe-static-init.html

Useful on cppreference.com:

这篇关于我如何知道C ++编译器是否生成线程安全的静态对象代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆