6

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.

Byoungchan Lee
  • 1,372
  • 13
  • 28

1 Answers1

3

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:

Community
  • 1
  • 1
Mihayl
  • 3,821
  • 2
  • 13
  • 32
  • Thanks. p0096r4 and https://github.com/llvm-mirror/clang/commit/6a95db8f1217ac08757e05fc6345fb8818f4eef1 was't existed when I asked this question. – Byoungchan Lee Nov 30 '17 at 13:08
  • Is quite new for me. Found while researching for https://stackoverflow.com/q/47569145/8918119. Never tried it – Mihayl Nov 30 '17 at 13:10