1#include"iostream"2#include"windows.h"3 using namespacestd;4 5 classcworkerthread{6 Public:7 CWorkerThread (LPCTSTR m_szname): M_szname (M_szname), M_hthread (INVALID_HANDLE_VALUE) {8M_hthread=CreateThread (9 NULL,Ten 0, One ThreadProc, AReinterpret_cast<lpvoid> ( This), - 0, - NULL the ); - } - - Virtual~CWorkerThread () {CloseHandle (m_hthread);} + - Virtual voidwaitforcompletion () { + WaitForSingleObject (m_hthread,infinite); A } at - Virtual voidSetPriority (intnpriority) { - setthreadpriority (m_hthread,npriority); - } - - Virtual voidSuspend () { in SuspendThread (m_hthread); - } to + Virtual voidResume () { - ResumeThread (m_hthread); the } * $ protected:Panax Notoginseng StaticDWORD WINAPI ThreadProc (lpvoid lpparam) { -CWorkerThread *pthis= theReinterpret_cast<cworkerthread*>(Lpparam); + APthis->Dostuff (); the return(0); + } - $ Virtual voidDostuff () { $ for(intn=0;n< -; n++){ -printf"Thread%s Id:%d,count%d\n", M_szname,getcurrentthreadid (), n); - } the } - Wuyi protected: the HANDLE M_hthread; - LPCTSTR M_szname; Wu }; - About voidMain () { $ -CWorkerThread WtB ("B"); -CWorkerThread WtA ("A"); - wta.setpriority (thread_priority_lowest); A + the wta.waitforcompletion (); - wtb.waitforcompletion (); $ thecout<<"Both threads complete."<<Endl; the the GetChar (); the}