windows系统调用 线程创建

 #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();
}
上一篇:boost dijkstra获得两点间的最短路


下一篇:Java 8函数编程轻松入门(四)方法引用