#include "thread_pool.h"
#include <iostream>
#include <vector>
#include <thread>
#include <list>
#include <mutex>
using namespace std;
mutex res_mux;
class MyCSA
{
private:
MyCSA() {};
static MyCSA *m_instance;
mutex mux;
public:
static MyCSA *getInstance()
{
if (m_instance == NULL)
{
std::unique_lock<mutex>mymux(res_mux);
if (m_instance == nullptr)
{
m_instance = new MyCSA();
static ReleaseC l;
}
}
return m_instance;
}
class ReleaseC
{
public:
~ReleaseC()
{
if (MyCSA::m_instance)
{
delete MyCSA::m_instance;
MyCSA::m_instance = nullptr;
}
}
};
};
MyCSA *MyCSA::m_instance = NULL;
int main()
{
MyCSA*p_a = MyCSA::getInstance();
MyCSA*p_b = MyCSA::getInstance();
cout << "I love China!" << endl;
}
|