Home » Operating Systems » Operating systems miscellaneous » Question

Operating systems miscellaneous

  1. Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores Sx and Sy respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows :

    In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively
    1. P(Sy), P(Sx), P(Sx), P(Sy)
    2. P(Sx), P(Sy), P(Sy), P(Sx)
    3. P(Sx), P(Sx), P(Sy), P(Sy)
    4. P(Sx), P(Sy), P(Sx), P(Sy )
Correct Option: D

Here semaphores are required to obtain mutual exclusion since both access X & Y. So at L1 P(Sx) which means now Sx = wait at L2 P(Sy) Sy wait, this prevents process P2 to start access X &Y. V(Sx) & V(Sy) in the end of P1 makes Sx & Sy signal so that at L3 & L4 P(Sx) & P(Sy) can start. Hence (d) is correct option.



Your comments will be displayed only after manual approval.