This commit is contained in:
Light-City
2020-02-07 13:42:44 +08:00
parent 5b5e3bc288
commit 60af6600e4
17 changed files with 505 additions and 10 deletions

View File

@@ -0,0 +1,25 @@
//
// Created by light on 20-2-7.
//
#include <iostream>
using namespace std;
#include <mutex>
class singleton {
private:
singleton() {}
static singleton *p;
static mutex lock_;
public:
static singleton *instance();
};
singleton *singleton::p = nullptr;
singleton* singleton::instance() {
lock_guard<mutex> guard(lock_);
if (p == nullptr)
p = new singleton();
return p;
}