Binary semaphores - Example - Operating System

Q.  The program given below consists of three concurrent processes P0, P1, P2 and three binary semaphores with the values S0 = 1, S1 = 0, S2 = 0.
How many times the process P0 will print ‘0’ ?

- Published on 27 Aug 15
computer-science-24.png


a. At least thrice
b. Exactly thrice
c. At least twice
d. Exactly twice

ANSWER: At least twice
 

    Discussion

  • Nirja Shah   -Posted on 18 Nov 15
    - At the initial stage only P0 can go inside the while loop as S0 = 1, S1 = 0, S2 = 0.

    - P0 will print ‘0’ first then, after releasing S1 and S2, either P1 or P2 will execute and release S0. So 0 is printed again.

    - Hence,'0' will be printed atleast twice.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)