CS FundamentalsVery hardGATE CS

A producer runs `repeat 3 { wait(empty); print('p'); signal(full); }` and a consumer runs `repeat 3 { wait(full); print('c'); signal(empty); }`, with empty = 2 and full = 0. How many distinct output strings are possible?

  1. A. 4
  2. B. 3
  3. C. 6
  4. D. 20

Correct answer: A. 4

Every prefix must have #c ≤ #p (full) and #p − #c ≤ 2 (buffer of 2). Counting strings of three p's and three c's meeting both constraints gives 4: pcpcpc, pcppcc, ppccpc, ppcpcc.

More Operating Systems questions

Exams that ask this topic