745 views
3 votes
3 votes
Let s be the binary semaphore variable and is equal to 1 initially. Assume that there are no blocked process in the system. If The following operation performed in the given order then how many blocked processes are present in the system at the end

7v, 15p,14v,10p,21v,15p

0

14

20

12

1 Answer

Best answer
6 votes
6 votes

For this we have to understand the implementation details of P() and V() in case of a binary semaphore . For P() , if the suspend list of process is empty , and a process calls P() operation then it is successful P() operation and as a result the value of the semaphore is set to 0. If further P() is called by any process , then this will be unsuccessful P() operation and the corresponding process will be blocked and put the suspended list of that semaphore.

As far as V() is concerned , if suspend list of the concerned semaphore is empty , the semaphore value is set to 1.Else one of the suspended process from the suspend list is freed using wakeup() call. If semaphore value is 1 already , it will remain to be 1.

Now we come to sequence of P() and V() calls given in the question.

a) 7V() : This will lead to semaphore value = 1  as s(semaphore variable) is set to 1 initially itself.

b) 15P() : First P() will be successful and s becomes 0 now . Now for each of the subsequent 14 P() calls , they will be unsuccessful and hence 14 processes will be now in block list.

c) 14V() : Now using each V() call , we can free one process from block list . As we have 14V() operations , we can free each of 14 processes which were blocked in earlier step . Thus after 14V() operations , 14 processes are freed . But s value is still 0.

d) 10P() : As s value is 0 , hence all of 10P() operations will be unsuccessful and again 10 processes will be suspended.

e) 21V() : In these 21V() , 10V() would be used for freeing the 10 suspended processes in earlier step.In the 11th V() call , s is set to 1 on checking that the suspended list is empty. All subsequent V() calls will keep the value of s to 1 only.

f) 15P() : As s value is 1 , the first P() will  be successful and s value is now again set to 0.After this each of the 14P() will lead to suspending of process only.Thus we are left with 14 blocked processes at the end.

Hence number of blocked processes at the end  =   14

selected by

Related questions

0 votes
0 votes
1 answer
1