参考文章:http://blog.csdn.net/huyiyang2010/archive/2010/08/10/5801597.aspx
1 // CThread.h 2 3 #ifndef __MY_THREAD_H__ 4 #define __MY_THREAD_H__ 5 6 #include <windows.h> 7 #include <process.h> 8 9 // 线程执行接口 10 class CRunnable 11 { 12 public: 13 CRunnable(){} 14 virtual ~CRunnable() {} 15 virtual void Run() = 0; 16 }; 17 18 class CThread : public CRunnable 19 { 20 enum 21 { 22 enmMaxThreadNameLen = 64, 23 }; 24 private: 25 explicit CThread(const CThread & rhs); 26 public: 27 CThread(); 28 CThread(CRunnable * pRunnable); 29 30 ~CThread(void); 31 bool Start(); 32 virtual void Run(); 33 void Join(int timeout = -1); 34 void Resume(); 35 void Suspend(); 36 bool Terminate(unsigned long ExitCode); 37 void dump(); 38 unsigned int GetThreadID(); 39 friend bool operator==(const CThread& left,const CThread& right); 40 private: 41 static unsigned int WINAPI StaticThreadFunc(void * arg); 42 void init(); 43 private: 44 HANDLE m_hHandle; 45 CRunnable * const m_pRunnable; 46 unsigned int m_nThreadID; 47 volatile bool m_bRun; 48 }; 49 50 #endif