How to call 3 threads sequentially many times?

Posted by Hello on Stack Overflow See other posts from Stack Overflow or by Hello
Published on 2012-10-24T04:39:48Z Indexed on 2012/10/24 5:01 UTC
Read the original article Hit count: 131

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about c++

Related posts about c