Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does clang++ do threadsafe initialisation of local static variables?

Tags:

c++

clang

clang++

Does clang++ do threadsafe initialisation of local static variables?

GCC does, unless you turn it off with the misleadingly named -fno-threadsafe-statics. I'm using Apple clang version 2.0 (tags/Apple/clang-139) (based on LLVM 2.9svn).

like image 674
James Avatar asked Dec 31 '25 11:12

James


2 Answers

Yes, same as with GCC (so can also be turned off with -fno-threadsafe-statics)

like image 80
cmeerw Avatar answered Jan 03 '26 00:01

cmeerw


Yes, although Apple's libcppabi implements this in a suboptimal way: with a global mutex which harms performance if many threads are using many local statics.

Source code: http://www.opensource.apple.com/source/libcppabi/libcppabi-26/src/cxa_guard.cxx

Bug report: https://bugreports.qt.io/browse/QTBUG-33967 (which led Qt to implement this differently when libcppabi is used).

I hope making more people aware of this will result in Apple fixing their code one day...

like image 26
David Faure Avatar answered Jan 02 '26 23:01

David Faure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!