CS FundamentalsVery hardGATE CS (PYQ pattern)

Semaphores s = 1, t = 0. P1: wait(s); print A; print B; signal(s). P2: wait(s); print C; signal(s). P3: wait(t); print D; signal(s). P4: print E; signal(t). All run concurrently, prints are atomic. How many different complete outputs are possible, and can the system deadlock?

  1. A. 26 outputs; no deadlock
  2. B. 23 outputs; deadlock possible
  3. C. 19 outputs; deadlock possible
  4. D. 23 outputs; no deadlock

Correct answer: D. 23 outputs; no deadlock

A and B are consecutive (P1 holds s). D needs t, i.e. E must come first, and D's signal(s) adds an extra permit. Exhaustive enumeration of schedules gives 23 outputs; deadlock reachable: False.

More Operating Systems questions

Exams that ask this topic