• edited by
4,451 views
7 7 votes

A counting semaphore was initialized to $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$

2 Answers

Best answer
3 3 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
7 7 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:
Position:
Show:

Related questions

1 1 vote
2 2 answers
5.0k
5.0k views
gatecse asked Dec 17, 2017
4,970 views
The characters of the string $\text{K R P C S N Y T J M}$ are inserted into a hash table of the size of size $10$ using a hash function$h(x)=(ord(x)-ord(A)+1)$ $mod$ $10$...
1 1 vote
6 answers 6 answers
4.5k
4.5k views
gatecse asked Dec 17, 2017
4,452 views
The proposition $(P\Rightarrow Q)\wedge (Q\Rightarrow P)$ is aTautologyContradictionContingencyAbsurdity
5 5 votes
3 answers 3 answers
2.1k
2.1k views
gatecse asked Dec 17, 2017
2,073 views
Consider a disk sequence with $100$ cylinders. The request to access the cylinder occur in the following sequence :$4,34,10,7,19,73,2,15,6,20$Assuming that the head is cu...
3 3 votes
1 1 answer
4.2k
4.2k views
gatecse asked Dec 17, 2017
4,215 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...