How to call 3 threads sequentially many times?
- by Hello
How to call 3 threads sequentially many times? For example: In iteration 1, execution order should be "Thread0-thread1-thread2" then in iteration 2 should be same i.e "Thread0 - thread1-thread2" and so on. The sample code is just executing 3 threads only once. It is not going to 2nd iteration.
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