There are three processes P1, P2 and P3 sharing a semaphore for synchronizing a variable. Initial value of semaphore is one. Assume that negative value of…
There are three processes P1, P2 and P3 sharing a semaphore for synchronizing a variable. Initial value of semaphore is one. Assume that negative value of semaphore tells us how many processes are waiting in queue. Processes access the semaphore in following order :
(A) P2 needs to access
(B) P1 needs to access
(C) P3 needs to access
(D) P2 exits critical section
(E) P1 exits critical section
The final value of semaphore will be :
Show answerHide answer
Correct answer: (A) 0
Explanation
Initial value S = 1. (1) P2 needs to access: S = 0 (no one waiting) (2) P1 needs to access: S = –1 (one process waiting) (3) P3 needs to access: S = –2 (two processes waiting) (4) P2 exits critical section: S = –1 (one process waiting) (5) P1 exits critical section: S = 0 (no process waiting)