6,067 views
1 votes
1 votes
Let S be the binary semaphore variable S = 0 initially. Assume that no blocked processes exist in the system. The following signal (V), wait (P) operations are performed. The number of blocked processes at the end are _________.

                                                            4 P, 6 V, 9 P, 13 V, 14 P

Answer given is 13 How? I am getting 8.

3 Answers

Best answer
14 votes
14 votes
13 is correct answer!

S is binary semaphore can have either 0 or 1 value.

Initially S=0

4 P:  4 blocked processes

6 V: S=1 & 0 blocked process

9 P:8 blocked processes

13 V: S=1 & 0 blocked process

14 P:  S=0 and 13 blocked processes
selected by
2 votes
2 votes
Answer is 13 .

Interesting question

Here Semaphore is Binary ( Main thing to note )

So if S=0 and if down or P or wait is performed on S it will remain 0 irrespective of the count of down performed in continous order

and if S=1 and if up or V or signal is perforned on S it will remain 1  irrespective of the count of UP performed in continous order

So , here s=0 intitally

1) 4p i.e 4 down on S , s will remain 0 but 4 process will get blocked

2) 6v i.e 6 up on S , s will raise to 1 and all 4 process will get unblock and will execute

3) 9p i.e 9 down on S, s will decement to 0 after 1 down and rest 8 down will cause 8 process to get blocked

4)13 V i.e 13 up on S , s will increment to 1 and will unblock all the 8 processes

5) 14P i.e 14 down on S , it will decrement S  to 0 after 1 down and rest all 13 down will cause 13 processes to get blocked.
1 votes
1 votes
Answer is 8 only, the solution provided in key might be wrong.

Related questions