![]() |
SpawnThreads() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Private Function |
Declared in: SocketThreadManager.h |
void SpawnThreads();
Spawn the threads
try { //Start creating threads //Allocate the thread structure m_pThreadData=new ThreadData[m_iThreadCount]; //And initialize it memset(m_pThreadData,0,sizeof(ThreadData)*m_iThreadCount); //Wait for all threads HANDLE* pHandle; pHandle=new HANDLE[m_iThreadCount]; //Reset them memset(pHandle,0,sizeof(HANDLE)*m_iThreadCount); //Start spawning for (int iCounter=0;iCounter<m_iThreadCount;++iCounter) { //Create an event m_pThreadData[iCounter].hEvent=CreateEvent(NULL,FALSE,FALSE,NULL); //Save it to our array pHandle[iCounter]=m_pThreadData[iCounter].hEvent; //Set our instance m_pThreadData[iCounter].hInstance=m_hInstance; //And create it m_pThreadData[iCounter].pThread=COSManager::CreateThread(SocketThread); //Check the thread has been created if (!m_pThreadData[iCounter].pThread->GetThreadID()) { //Report the error ReportError("SpawnThreads","Failed to create thread!"); //Delete the handle array CleanThreads(); //Quit return; } else //Start the thread m_pThreadData[iCounter].pThread->Start((LPVOID)&m_pThreadData[iCounter]); } //Wait for all the handles to finish if (WaitForMultipleObjectsEx(m_iThreadCount,pHandle,TRUE,10000,FALSE)==WAIT_TIMEOUT) //Report the error ReportError("SpawnThreads","Timeout waiting for threads!"); //Release all the events for (iCounter=0;iCounter<m_iThreadCount;++iCounter) CloseHandle(pHandle[iCounter]); //Delete all the handles delete [] pHandle; } ERROR_HANDLER("SpawnThreads")
![]() |
Site content copyright © 2001 Barak Weichselbaum. See the About page for additional notices. This page last updated: 27 Jun 2001. |