![]() |
SpawnThreads() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Private Function |
Declared in: ThreadPool.h |
BOOL SpawnThreads( LPInitializePoolProc pInitializeProc, CGenericThread::ThreadPriority aPriority);
Create the threads
try { //Create the thread list m_ppThreads=new CGenericThread*[m_ulThreadCount]; //Create the thread data m_ppThreadData=new ThreadData*[m_ulThreadCount]; //Clear the data memset(m_ppThreads, 0, sizeof(CGenericThread*)*m_ulThreadCount); memset(m_ppThreadData, 0, sizeof(ThreadData*)*m_ulThreadCount); //Our waiting list CWaitList aWaitingList; //Create each thread for (int iCount=0;iCount<m_ulThreadCount;++iCount) { m_ppThreadData[iCount]=new ThreadData; //Create the event m_ppThreadData[iCount]->pEvent=COSManager::CreateEvent(); m_ppThreadData[iCount]->pExitEvent=COSManager::CreateEvent(); //Add it to the waiting list aWaitingList.AddObject(m_ppThreadData[iCount]->pEvent,TRUE); //Set our class m_ppThreadData[iCount]->pClass=this; //The initialize proc m_ppThreadData[iCount]->pInitializeProc=pInitializeProc; //Create the thread m_ppThreads[iCount]=COSManager::CreateThread(PoolThread); //Set the priority m_ppThreads[iCount]->SetPriority(aPriority); //Start it m_ppThreads[iCount]->Start((LPVOID)m_ppThreadData[iCount]); } //Did we have an error BOOL bError; bError=FALSE; //Wait for all the handles to finish DWORD dwTmp; if (aWaitingList.Wait(TRUE, dwTmp, THREAD_TIMEOUT)) { //Report the error ReportError("SpawnThreads","Timeout waiting for threads!"); //Indicate it bError=TRUE; } //Done return !bError; } ERROR_HANDLER_RETURN("SpawnThreads",FALSE)
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |