1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| INT_PTR nIndexThread;
while(arThreads.GetCount() > 0)
{
// on rend la main au système
Sleep(1);
// puis on parcours les threads du dernier au premier
nIndexThread = arThreads.GetUpperBound();
for(; nIndexThread >= 0; nIndexThread--)
{
// récupération de l'état du thread
GetExitCodeThread(arThreads[nIndexThread]->m_hThread, &nResult);
// si le thread est actif
if(nResult == STILL_ACTIVE)
continue; // on passe au suivant
// si le thread n'est plus actif
// on regarde s'il y a encore des questions à traiter
if(nIndexQues < arQuestions.GetCount())
{
// on paramètre la nouvelle question à gérer
arParams[nIndexThread]->pQuesQuestion = arQuestions[nIndexQues++];
// et on relance le thread
delete arThreads[nIndexThread];
arThreads[nIndexThread] = AfxBeginThread(CAFF_FileSDic::MatchQuestionThread, arParams[nIndexThread], THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
arThreads[nIndexThread]->m_bAutoDelete = false;
arThreads[nIndexThread]->ResumeThread();
}
else // plus de questions à traiter
{ // suppression du thread et de ses params
delete arThreads[nIndexThread];
arThreads.RemoveAt(nIndexThread);
delete arParams[nIndexThread];
arParams.RemoveAt(nIndexThread);
}
}
}; |