困惑ing
Class A
{
public:
~A(){}
static A* getInstance()
{
if(_instance==NULL)
void func
{
}
private:
static A* _instance;
private:
A(){}
};
这样一个单例模式的类A,如果有2个线程thread1 和 thread2 都同时访问它通过A::getInstance()->func()的方式调用了func函数,这时会发生什么事情呢?
Class A
{
public:
~A(){}
static A* getInstance()
{
if(_instance==NULL)
_instance=new A;
return _instance;
}
return _instance;
void func
{
}
private:
static A* _instance;
private:
A(){}
};
这样一个单例模式的类A,如果有2个线程thread1 和 thread2 都同时访问它通过A::getInstance()->func()的方式调用了func函数,这时会发生什么事情呢?