October 3, 2023
October 3, 2023
October 3, 2023
###### Algorithms
October 3, 2023
 Question 21
Consider the following threads, T 1 , T 2 , and T 3 executing on a single processor, synchronized using three binary semaphore variables, S 1 , S 2 , and S 3 , operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time.

Which initialization of the semaphores would print the sequence BCABCABCA….?
 A S 1 = 1; S 2 = 1; S 3 = 1 B S 1 = 1; S 2 = 1; S 3 = 0 C S 1 = 1; S 2 = 0; S 3 = 0 D S 1 = 0; S 2 = 1; S 3 = 1
Question 21 Explanation:
Explanation: Since B is to be printed first semaphore S1 has to be set to 1, so that the thread enters its critical section and prints B. Then C needs to be printed, this happens when Thread 1 is blocked on semaphore s3 (blocked, s3=0). Then Thread1 invokes Thread 3 to print A.
Question 21 Explanation:
Explanation: Since B is to be printed first semaphore S1 has to be set to 1, so that the thread enters its critical section and prints B. Then C needs to be printed, this happens when Thread 1 is blocked on semaphore s3 (blocked, s3=0). Then Thread1 invokes Thread 3 to print A.