ACE的Double-checked-locking的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;


posted @ 2012-01-07 21:15  小 楼 一 夜 听 春 雨  阅读(351)  评论(0编辑  收藏  举报