Skip to content

Instantly share code, notes, and snippets.

View romualdo97's full-sized avatar

Romualdo VIllalobos romualdo97

View GitHub Profile
@louis-langholtz
louis-langholtz / cpp-thread-safe-initialization.md
Last active June 29, 2025 20:58
C++ Requires Thread Safe Initialization of Block-Scope Variables With Static or Thread Storage Duration

C++: Thread Safe Initialization Requirements

Seems like this has come up for me enough in discussing C++ with others, that it might help to put together the information in this gist.

Standard C++ has since C++11 required that block-scope variables with static or thread storage duration get initialized in a thread safe way. Besides there being a StackOverflow answer - to a related question - showing some example assembly for C++11 that includes thread safe guards, there's also the C++ standard documents themselves.

What follows is the specific requirement by versions of the standard.

C++03