???????????????????????????????
?????????????????????ε??????????????????????μ???????????????????????????
????????????????????????????????????????????ж????????????????if??????non thread safety.
???????double-check?????thread safety.???????????????????????????????????????????
????1?????????????????????
1 class Singleton
2 {
3 private:
4     static Singleton* m_instance;
5     Singleton(){}
6 public:
7     static Singleton* getInstance();
8 };
9
10 Singleton* Singleton::getInstance()
11 {
12     if(NULL == m_instance)
13     {
14         Lock();//??????????????????boost
15         if(NULL == m_instance)
16         {
17             m_instance = new Singleton;
18         }
19         UnLock();
20     }
21     return m_instance;
22 }
????2???????????????????
??????????????????C++0X???????????????????????????????????????????????C++ 0X????????????????
????1 class SingletonInside
????2 {
????3 private:
????4     SingletonInside(){}
????5 public:
????6     static SingletonInside* getInstance()
????7     {
????8         Lock(); // not needed after C++0x
????9         static SingletonInside instance;
????10         UnLock(); // not needed after C++0x
????11         return instance;
????12     }
????13 };