CS FundamentalsHardGATE CS (PYQ pattern)

Binary semaphore m is initialised to 1. P1: P(m); print A; V(m); print B. P2: P(m); print C; V(m); print D. P3: P(m); print E; V(m). All three start together and may interleave arbitrarily. How many distinct output strings can be produced?

  1. A. 24
  2. B. 30
  3. C. 36
  4. D. 60

Correct answer: B. 30

Only the program orders A<B, C<D (and the lock-serialised prints A, C, E, which can occur in any order) constrain the output. Counting all interleavings of the three programs with the lock enforced gives 30 distinct strings.

More Operating Systems questions

Exams that ask this topic