recategorized by
3,131 views
6 votes
6 votes

A counting semaphore was initialized t o $7$. Then $\text{20 P (wait)}$ operations and$\text{x V (signal)}$ operations were completed on this semaphore. If the final value of semaphore is $5$, then the value $x$ will be

  1. $0$
  2. $13$
  3. $18$
  4. $5$
recategorized by

2 Answers

Best answer
2 votes
2 votes

Counting  semaphore is a protected variable whose value can be changed only by predefined atomic operations

  • Wait :- P(Sem s) Decrements value of S by 1. If S<=0, the thread must go for sleep and get inserted in wait_queue
  • Signal: V(Sem s) Increments value of S by 1 and wakes up one of the threads in waiting queue. 

In given problem

  • Initially value =  7
  • After 20 P (wait) operations, value = 7- 20 = -13
  • After x V (signal) operations, value = -13+x =5
  • x = 5+13 =18

Answer is C

selected by
6 votes
6 votes
it should be 18

P refers to down operation and V refers to up i.e 7-20(P)+x(V)=5

=> x = 18
Answer:

Related questions

2 votes
2 votes
1 answer
2
gatecse asked Dec 17, 2017
2,923 views
Consider the following table :$\begin{array}{|l|l|l|} \hline \textbf{A.} & \text{Activation record} & \textbf{p.} & \text{Linking loader} \\\hline \textbf{B.} & \text{Loc...