#include "windows.h"
#include "iostream"
using namespace std;
class CWorkerThread{
public:
CWorkerThread(LPCTSTR szName):
m_szName(szName),m_hThread(INVALID_HANDLE_VALUE){
m_hThread=CreateThread(
NULL,
,
ThreadProc,
reinterpret_cast<LPVOID>(this),
,
NULL
);
}
virtual ~CWorkerThread(){
CloseHandle(m_hThread);
}
virtual void WaitForCompletion(){
WaitForSingleObject(m_hThread,INFINITE);
}
protected:
static DWORD WINAPI ThreadProc(LPVOID lpParam){
CWorkerThread *pThis=reinterpret_cast<CWorkerThread *>( lpParam);
pThis->DoStuff();
return ;
}
virtual void DoStuff(){
for(int n=;n<;++n){
printf("Thread %s ID:%d,count %d\n",m_szName,GetCurrentThreadId(),n);
}
}
protected:
HANDLE m_hThread;
LPCTSTR m_szName;
};
void main(){
CWorkerThread wtA("A");
CWorkerThread wtB("B");
wtA.WaitForCompletion();
wtB.WaitForCompletion();
printf("Both threads complete.\n");
getchar();
}