#ifdef WIN32
class Thread
{
public:
Thread ( DWORD (WINAPI * pFun) (void* arg), void* pArg)
{
_handle = CreateThread (
0, // Security attributes
0, // Stack size
pFun,
pArg,
CREATE_SUSPENDED,
&_tid);
}
~Thread () { CloseHandle (_handle); }
void Resume () { ResumeThread (_handle); }
void WaitForDeath (int nTimeOut)
{
if (nTimeOut==INFINITE) WaitForSingleObject (_handle,INFINITE);
else WaitForSingleObject (_handle, nTimeOut*1000);
}
int nTimeOut;
private:
HANDLE _handle;
DWORD _tid; // thread id
};
#endif
사용방법
thread_func_args pthread_args(tcp_proc,socket_array[nConnection_Count-1]);
Thread thr(&CTCPComm::ValidateData_Client,&pthread_args);
thr.nTimeOut=3;
thr.Resume();
thr.WaitForDeath();
윈도우즈에서 Thread Hang이 사라짐..퍼포먼스 그런대로 괜찮음...