Thread-Safe Initialization - Static Variables with Block Scope

This lesson gives an overview of thread-safe initialisation with static variables in the perspective of concurrency in C++.

We'll cover the following

Static variables with block scope will be created exactly once and lazily (i.e. created just at the moment of the usage). This characteristic is the basis of the so-called Meyers Singleton, named after Scott Meyers. This is by far the most elegant implementation of the singleton pattern. With C++11, static variables with block scope have an additional guarantee; they will be initialized in a thread-safe way.

Thread-safe example:

Here is the thread-safe Meyers Singleton pattern.

Get hands-on with 1000+ tech skills courses.