in Operating System recategorized by
3,150 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$
in Operating System recategorized by
by
3.2k views

4 Comments

option c
0
0
answer key they have given as b..
0
0
In revised key answer is changed to C
0
0
Shiva

Give me link of revised answer key??
0
0

2 Answers

2 votes
2 votes
Best answer

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
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

4 Comments

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

=> x = 18
0
0
in answer put it
1
1
Smart representation. I'm noting it down as a formula
0
0
Answer:

Related questions