Skip to content

Instantly share code, notes, and snippets.

@zno5
Created November 4, 2016 15:30
Show Gist options
  • Save zno5/a170304d0d62b80c2e6e23a395a3362a to your computer and use it in GitHub Desktop.
Save zno5/a170304d0d62b80c2e6e23a395a3362a to your computer and use it in GitHub Desktop.
singleton class using std::call_once
#include <mutex>
class MySingleton {
public:
static MySingleton * GetInstance() {
std::call_once(
m_flag,
[] () { m_instance = new MySingleton(); }
);
return m_instance;
}
private:
static MySingleton * m_instance;
static std::once_flag m_flag;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment