c++ thread

 HANDLE m_hThread;
 HANDLE m_hQuitEvent;
 static unsigned __stdcall ProcessData (LPVOID pParam);


m_hQuitEvent = CreateEvent( NULL,TRUE,FALSE,NULL );
    m_hThread =
     (HANDLE)_beginthreadex(NULL,    // Security
     0,     // Stack size - use default
     ProcessData,     // Thread fn entry point
     (void*) this,    
     0,     // Init flag
     NULL);


  SetEvent( m_hQuitEvent );
unsigned __stdcall CIOCP::ProcessData(LPVOID pParam)
{
 CIOCP* pThis = (CIOCP*)pParam;
 if (pThis == NULL)
 {
  return FALSE;
 }
 while(TRUE)
 {  
  DWORD dwWaitResult = WaitForSingleObject(pThis->m_hQuitEvent,1000);
  switch (dwWaitResult)
  {
  case WAIT_OBJECT_0:
   return 1;
  case WAIT_TIMEOUT:
   break;
  }
 }
}

你可能感兴趣的:(c++ thread)