edited by
1,424 views
6 votes
6 votes
Let S be a binary semaphore variable, S=0

What will be the value of S when following operations are performed:-

2P, 4V, 5P, 2P, 8V, 3P, 2V  ?
edited by

1 Answer

Best answer
7 votes
7 votes
Answer is 0.

initially s=0.

Now, 2P makes 2 processes waiting in queue

4V signals will make 2 of them to complete and final value of s=1 now

5P processes one of them will make s=0 and other 4 will wait

2P process further wait making in all 6 processes to wait

8V will make them complete and finally 2V extra signals make s=1

3P, 1p will complete s=0 and 2P will wait

2V will make them to complete and since no extra signal i.e., V so s remains 0
selected by

Related questions