Safe Static Initialisation & Clean Up in Libraries
summary
Explains how C++17+ initializes static storage: constant values go to data/rodata, zeroed ones to BSS, and anything else triggers runtime code pushed into the init array that runs before main and registers destructors with atexit. Shows the cost of dynamic local statics (atomic guard, double-checked lock) and the static-order fiasco. Recommends avoiding dynamic initialization, using compile-time constants, or exposing a small RAII handle (library init/cleanup object + pImpl and a nifty counter for external deps) to control lifetime reliably.
AI-written summary Β· about
chapters (13)
- 0:00Introduction to talk
- 2:00Static storage duration basics
- 7:00Program loading and segments
- 12:56Initialization phases explained
- 16:51Assembly view of initialization
- 21:07Linking and dynamic initialization
- 24:37Static local variables
- 28:11Constructors and destructors
- 30:40Common initialization patterns
- 37:05Library linking and loading
- 39:36Safe library initialization
- 43:54Example library design
- 52:00Q&A session
related talks
01h 01mInitialization, Shutdown, and constexpr
11mLightning talk: Manual (de)initialization A Rust and C++
58mStorage Duration and Linkage in C and C++
01h 29mWhat Does It Take to Implement the C++ Standard Library?
54mTypical C++, But Why?
32mCute C++ Tricks, Part 2 of N: More code you should learn from and never write
01h 33mSafe and Sane C++ Types
53mβThe Importance of Being const"
