Related Articles
UGC-NET | UGC NET CS 2017 Jan – II | Question 36
• Last Updated : 26 Mar, 2018

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 :
(A) 0
(B) 1
(C) -1
(D) -2

Explanation: Initial value of semaphores S=1

1. P2 needs to access decreases semaphore by 1, new value will be 0 (no one is waiting)
2. P1 needs to access decreases semaphore by 1, new value will be -1 (one process is waiting)
3. P3 needs to access decreases semaphore by 1, new value will be -2 ( 2 process are waiting)
4. P2 exits critical section increases semaphore by 1, new value will be -1 ( one process is waiting)
5. P1 exits critical section increases semaphore by 1, new value will be 0 ( no process is waiting)

So, option (A) is correct.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up