diff --git a/6.SingletonPattern/1.Picture/单例模式.vsdx b/6.SingletonPattern/1.Picture/单例模式.vsdx deleted file mode 100644 index 63881e9..0000000 Binary files a/6.SingletonPattern/1.Picture/单例模式.vsdx and /dev/null differ diff --git a/6.SingletonPattern/1.Picture/单例模式UML图.png b/6.SingletonPattern/1.Picture/单例模式UML图.png deleted file mode 100644 index df48d4e..0000000 Binary files a/6.SingletonPattern/1.Picture/单例模式UML图.png and /dev/null differ diff --git a/6.SingletonPattern/2.Code/Singleton.h b/6.SingletonPattern/2.Code/Singleton.h deleted file mode 100644 index 3ff8a6a..0000000 --- a/6.SingletonPattern/2.Code/Singleton.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __SINGLETON_H__ -#define __SINGLETON_H__ - -#include -#include -#include -using namespace std; - -class Singleton -{ -public: - static Singleton* getInstance(){ - if (instance == NULL){ - m_mutex.lock(); - if (instance == NULL){ - printf("µʵ\n"); - instance = new Singleton(); - } - m_mutex.unlock(); - } - return instance; - } -private: - Singleton(){} - - static Singleton* instance; - static std::mutex m_mutex; -}; - -Singleton* Singleton::instance = NULL; -std::mutex Singleton::m_mutex; - -#endif //__SINGLETON_H__ \ No newline at end of file diff --git a/6.SingletonPattern/2.Code/Singleton/Singleton.h b/6.SingletonPattern/2.Code/Singleton/Singleton.h deleted file mode 100644 index 3ff8a6a..0000000 --- a/6.SingletonPattern/2.Code/Singleton/Singleton.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __SINGLETON_H__ -#define __SINGLETON_H__ - -#include -#include -#include -using namespace std; - -class Singleton -{ -public: - static Singleton* getInstance(){ - if (instance == NULL){ - m_mutex.lock(); - if (instance == NULL){ - printf("µʵ\n"); - instance = new Singleton(); - } - m_mutex.unlock(); - } - return instance; - } -private: - Singleton(){} - - static Singleton* instance; - static std::mutex m_mutex; -}; - -Singleton* Singleton::instance = NULL; -std::mutex Singleton::m_mutex; - -#endif //__SINGLETON_H__ \ No newline at end of file diff --git a/6.SingletonPattern/2.Code/Singleton/main.cpp b/6.SingletonPattern/2.Code/Singleton/main.cpp deleted file mode 100644 index bee839c..0000000 --- a/6.SingletonPattern/2.Code/Singleton/main.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include "Singleton.h" - -/*ģʽʵ*/ -/* -int main() -{ - Singleton *s1 = Singleton::getInstance(); - Singleton *s2 = Singleton::getInstance(); - - system("pause"); - return 0; -} -*/ - -/*̰߳ȫ ģʽ*/ -#include -#include - -//̣߳߳Ŀ5 -#define THREAD_NUM 5 - -unsigned int __stdcall CallSingleton(void *pPM) -{ - Singleton *s = Singleton::getInstance(); - int nThreadNum = *(int *)pPM; - Sleep(50); - //printf("̱߳Ϊ%d\n", nThreadNum); - return 0; -} - - -int main() -{ - HANDLE handle[THREAD_NUM]; - - //̱߳ - int threadNum = 0; - while (threadNum < THREAD_NUM) - { - handle[threadNum] = (HANDLE)_beginthreadex(NULL, 0, CallSingleton, &threadNum, 0, NULL); - //߳̽յʱܸ߳̿ıiֵ - threadNum++; - } - //֤߳ȫн - WaitForMultipleObjects(THREAD_NUM, handle, TRUE, INFINITE); - - system("pause"); - return 0; -} \ No newline at end of file diff --git a/6.SingletonPattern/2.Code/main.cpp b/6.SingletonPattern/2.Code/main.cpp deleted file mode 100644 index bee839c..0000000 --- a/6.SingletonPattern/2.Code/main.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include "Singleton.h" - -/*ģʽʵ*/ -/* -int main() -{ - Singleton *s1 = Singleton::getInstance(); - Singleton *s2 = Singleton::getInstance(); - - system("pause"); - return 0; -} -*/ - -/*̰߳ȫ ģʽ*/ -#include -#include - -//̣߳߳Ŀ5 -#define THREAD_NUM 5 - -unsigned int __stdcall CallSingleton(void *pPM) -{ - Singleton *s = Singleton::getInstance(); - int nThreadNum = *(int *)pPM; - Sleep(50); - //printf("̱߳Ϊ%d\n", nThreadNum); - return 0; -} - - -int main() -{ - HANDLE handle[THREAD_NUM]; - - //̱߳ - int threadNum = 0; - while (threadNum < THREAD_NUM) - { - handle[threadNum] = (HANDLE)_beginthreadex(NULL, 0, CallSingleton, &threadNum, 0, NULL); - //߳̽յʱܸ߳̿ıiֵ - threadNum++; - } - //֤߳ȫн - WaitForMultipleObjects(THREAD_NUM, handle, TRUE, INFINITE); - - system("pause"); - return 0; -} \ No newline at end of file