CS FundamentalsModerateGATE CS

Binary semaphores S = Q = 1. P1: wait(S); wait(Q); print 1; signal(Q); signal(S). P2: wait(Q); wait(S); print 2; signal(S); signal(Q). Which statement is correct?

  1. A. Only 12 is possible
  2. B. Deadlock is impossible because both semaphores start at 1
  3. C. Outputs 12 and 21 are possible and deadlock is impossible
  4. D. Outputs 12 and 21 are possible, and deadlock is also possible

Correct answer: D. Outputs 12 and 21 are possible, and deadlock is also possible

If P1 gets S and P2 gets Q before either takes its second semaphore, each waits for the other: deadlock. If one finishes both waits first, it completes and the other follows, giving 12 or 21.

More Operating Systems questions

Exams that ask this topic