4,413 views
1 votes
1 votes
A counting semaphore S is created with initial value as 3.

Suppose 5 processes are calling P, what will be the final value of S?

A. 8

B. 0

C. -2

D. -1

2 Answers

Best answer
4 votes
4 votes
S=3 //initially means 3 process can enter and  live in CS simultaneously

then 5 P(down) operations so 3-5 =-2

Means 3 have entered CS successfully but rest 2 process are blocked and kept in Block Queue.

So final value of S=-2.
selected by
2 votes
2 votes

answer  is  -2  

in case of counting semaphore  

the value represented by semaphore tells---   the number of process  that  can enter into    Critical Section

here the value was  3   so at max 3  process can enter  and before entering they decrement counter and check if it

is less than 0.

and after that every process will wait in waiting  queue   and  P  is  down operation or  decrement on semaphore

eg--

current semaphore  value  V(3 )

process -- PR( )

V(3) --- PR(1)     perforn   down  P  ,checks if  V() < 0,  enter into   CS 

V(2) ---- PR(2)       perforn   down  P,checks if  V() < 0 ,  enter into   CS 

V(1) ---- PR(3)     perforn   down  P,checks if  V() < 0 ,  enter into   CS 

 V(0) ---- PR(4)   perform down P , checks if  V()<0   and  after  down value isV(-1)  

        PR(4)  Enter into waiting queue

V(-1)  ------ PR(5)  perform down P, checks if  V()<0   and  after  down value isV(-2)

           PR(5)   enter into  waiting queue

V(-2) 

hence value is -2

Related questions