如何多次顺序调用3个线程?例如:在迭代 1 中,执行顺序应该是“Thread0->thread1->thread2”,然后在迭代 2 中应该是相同的,即“Thread0 -> thread1->thread2”等等。示例代码只执行一次 3 个线程。它不会进行第二次迭代。
Thread0 = CreateThread( NULL,0,ThreadProc0, NULL, CREATE_SUSPENDED, &ThreadID);
Thread1 = CreateThread( NULL,0,ThreadProc1, NULL, CREATE_SUSPENDED, &ThreadID);
Thread2 = CreateThread( NULL,0,ThreadProc2, NULL, CREATE_SUSPENDED, &ThreadID);
for(i=0;i<iterations;i++) //Iterations in calling threads
{
ResumeThread(Thread0);
WaitForSingleObject(Thread0, INFINITE);
ResumeThread(Thread1);
WaitForSingleObject(Thread1, INFINITE);
ResumeThread(Thread2);
WaitForSingleObject(Thread2, INFINITE);
}
// Close thread and semaphore handles