CS FundamentalsVery hardProduct company interview · GATE level

Semaphores a = 0 and b = 0. Three processes run concurrently: P: print('A'); signal(a); wait(b); print('B'); Q: wait(a); print('C'); signal(b); signal(a); R: wait(a); print('D'); signal(b); Which statement is correct?

  1. A. ACBD, ACDB and ADCB are all possible complete outputs
  2. B. The only complete outputs are ACBD and ACDB, and deadlock is impossible
  3. C. The only complete outputs are ACBD and ACDB, and the system can also deadlock after printing ADB
  4. D. The output is always ACBD

Correct answer: C. The only complete outputs are ACBD and ACDB, and the system can also deadlock after printing ADB

After A, the single signal(a) wakes either Q or R. If Q wins, it prints C, signals b and passes a on to R; P (waiting on b) and R then race, giving ACBD or ACDB. If R wins, it prints D and signals b, so P prints B, but nobody ever signals a again: Q waits forever after the output ADB. ADCB is impossible because C requires a, which only Q itself would re-signal.

More Operating Systems questions

Exams that ask this topic