UGC-NET | UGC NET CS 2017 Jan – II | Question 36
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
Answer: (A)
Explanation: Initial value of semaphores S=1
- P2 needs to access decreases semaphore by 1, new value will be 0 (no one is waiting)
- P1 needs to access decreases semaphore by 1, new value will be -1 (one process is waiting)
- P3 needs to access decreases semaphore by 1, new value will be -2 ( 2 process are waiting)
- P2 exits critical section increases semaphore by 1, new value will be -1 ( one process is waiting)
- 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
Last Updated :
26 Mar, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...