ACE的Doublecheckedlocking的Singleton


 1 class Singleton
2 {
3 private:
4 static Singleton* volatile instance_;
5 static ACE_Recursive_Thread_Mutex lock_;
6 protected:
7 Singleton() {}
8 public:
9 static Singleton* Instance()
10 {
11 if (instance_ == 0)
12 {
13 ACE_Guard<ACE_Recursive_Thread_Mutex> guard(lock_);
14 if (instance_ == 0)
15 instance_ = new Singleton;
16 }
17 return instance_;
18 }
19
20 };
21
22 Singleton* volatile Singleton::instance_ = 0;


原文地址:https://www.cnblogs.com/kex1n/p/2316021.html