Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::atomic<Singleton*> Singleton::m_instance;
- std::mutex Singleton::m_mutex;
- Singleton* Singleton::getInstance() {
- Singleton* tmp = m_instance.load();
- if (tmp == nullptr) {
- std::lock_guard<std::mutex> lock(m_mutex);
- tmp = m_instance.load();
- if (tmp == nullptr) {
- tmp = new Singleton;
- m_instance.store(tmp);
- }
- }
- return tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement