Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create threads here
- hT[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)T1, 0, CREATE_SUSPENDED, &t_id1);
- hT[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)T2, 0, CREATE_SUSPENDED, &t_id2);
- hT[2] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)T3, 0, CREATE_SUSPENDED, &t_id3);
- // create semaphores here
- //= CreateSemaphore(NULL, 0, 3, NULL);
- sm[0] = CreateSemaphore(NULL, 0, 3, NULL);
- sm[1] = CreateSemaphore(NULL, 0, 3, NULL);
- sm[2] = CreateSemaphore(NULL, 0, 3, NULL);
- void T1(void)
- {
- cout << "T1 STARTED" << endl;
- Sleep(1000);
- ReleaseSemaphore(sm[0], 3, NULL);
- WaitForMultipleObjects(3, sm, TRUE, INFINITE);
- cout << "T1 FINISHED" << endl;
- }
- void T2(void)
- {
- cout << "T2 STARTED" << endl;
- Sleep(2000);
- ReleaseSemaphore(sm[1], 3, NULL);
- WaitForMultipleObjects(3, sm, TRUE, INFINITE);
- cout << "T2 FINISHED" << endl;
- }
- void T3(void)
- {
- cout << "T3 STARTED" << endl;
- Sleep(3000);
- ReleaseSemaphore(sm[2], 3, NULL);
- WaitForMultipleObjects(3, sm, TRUE, INFINITE);
- cout << "T3 FINISHED" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement