Thread-Safe Singleton: Atomics

This lesson explains the solution for the thread-safe initialization of singleton problem using atomics in C++.

With atomic variables, my implementation becomes a lot more challenging; I can even specify the memory model for my atomic operations. The following two implementations of the thread-safe singletons are based on the previously mentioned double-checked locking pattern.

Sequential Consistency

In my first implementation, I use atomic operations without specifying the memory model; therefore, sequential consistency applies.

Get hands-on with 1000+ tech skills courses.