[英]How can I know if C++ compiler make thread-safe static object code?
在GCC中,除非給出-fno-threadsafe-statics
__cxa_guard_acquire
編譯器選項,否則本地靜態變量是線程安全的(通過特殊函數__cxa_guard_acquire
)。
同樣,MSVC 2015及更高版本支持相同的功能,可以通過/Zc:threadSafeInit-
禁用。
是否有任何宏或其他功能,如__EXCEPTIONS
或__GXX_RTTI
來檢查編譯階段是否啟用了這些功能? 我認為檢查__cplusplus
或_MSC_VER
無濟於事。
看起來有一個定義__cpp_threadsafe_static_init
。
SD-6:SG10功能測試建議 :
C ++ 11的功能
C ++ 11的重要功能
文檔。 編號標題主要部分宏名稱值標題
N2660並發動態初始化和銷毀3.6
__cpp_threadsafe_static_init
200806 預定義
鐺 - 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上有用:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.