3 ms·
> Furthermore, such initialization is thread safe so that one initialization happens despite multiple concurrent calls of the function. IIRC, there are some po
by cesarb 3y ago
> Furthermore, such initialization is thread safe so that one initialization happens despite multiple concurrent calls of the function.
IIRC, there are some popular compilers in which initialization of static variables inside functions is not thread safe (even though AFAIK the C++ standard said they should be).
- vlovich123 3y agoI’m not aware of this problem in MSVC, clang and gcc and those are the most popular afaik.
- cesarb 3y ago> I’m not aware of this problem in MSVC The compiler I was thinking of was indeed MSVC. From a quick web search, it seems that more recent versions of MSVC have changed them to be thread safe by default, so if you can make sure that your code will never be compiled on older MSVC versions (and that nobody will ever use the compiler option which disables the thread-safe initialization), it might be fine to depend on it.
- vlovich123 3y agoTrue as of msvc 2015 which is 8.5 years old at this point. I agree it’s weird that you can disable it but libraries retaining correctness in the face of random compiler flags is hard (eg ffast-math is a common one that can break your floating point library)