C++????????????
???????????? ???????[ 2015/7/31 11:32:08 ] ??????????????? ???????????
???????????????????????????????
?????????????????????ε??????????????????????μ???????????????????????????
????????????????????????????????????????????ж????????????????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 };
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11