This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Enable threadsafe static initialization (aka 'magic statics') #2375
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
C++11 guarantees that initialization of function statics will be
threadsafe. We disabled this by passing -fno-threadsafe-statics because
we used to support building using visual studio and older versions
(older than 2015) did not implement this functionality. Now we only use
modern toolchains which do support this and it's increasingly likely
that libraries we want to use and that other C++ developers will
expect rely on the standard behavior instead of our nonstandard init.
Using the toolchain's implementation of threadsafe initialization is
also very likely to be more efficient than our own handrolled
threadsafe initialization and less error prone.
With the specified behavior, many uses of base::Singleton for threadsafe
initialization can be replaced by function statics for a performance
boost. There's also a very slight risk that code that was depending on
racy initialization could break, but such code is at the very least
suspect if not outright broken already.
Equivalent change in Mojo is here: https://codereview.chromium.org/1683973002