Untitled
unknown
c_cpp
3 years ago
513 B
7
Indexable
class Singleton {
public:
static Singleton& getInstance() {
if (instance_ == nullptr) {
std::lock_guard<std::mutex> lock(mutex_);
if (instance_ == nullptr) {
instance_ = new Singleton();
}
}
return *instance_;
}
void doSomething() {
// ...
}
private:
Singleton() {}
static Singleton* instance_;
static std::mutex mutex_;
};
Singleton* Singleton::instance_ = nullptr;
std::mutex Singleton::mutex_;
Editor is loading...