Question 19Asked in UGC NET Computer Science, June 2017 (Paper II & III, Selected Questions)

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 :
  1. A0
  2. B1
  3. C–1
  4. D–2
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)

From UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions)

This is question 19 of UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.