How do you lazily construct a singleton object thread-safely? [duplicate]
Here’s Meyer’s singleton, a very simple lazily constructed singleton getter: Singleton &Singleton::self() { static Singleton instance; return instance; } This is lazy, and C++11 requires it to be thread-safe. In fact, I believe that at least g++ implements this in a thread-safe manner. So if that’s your target compiler or if you use a compiler … Read more