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?
- A. 4
- B. 3
- C. 6
- 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
- mutex m = 1. P1: wait(m); print A; print B; signal(m). P2: wait(m); print C; print D; signal(m). P3: print E (no synchronisation). How…
- Shared x = 0, mutex m = 1. T1: wait(m); x = x + 1; signal(m). T2: wait(m); x = x + 2; signal(m). T3: x = x + 4 (no lock). Each assignment…
- A counting semaphore is implemented WITHOUT busy waiting: wait() decrements the value and, if it becomes negative, puts the caller on the…
- Strict alternation uses a shared turn variable: P0: while (turn != 0); CS; turn = 1; P1: while (turn != 1); CS; turn = 0;. P0 wants to…
- Two processes each run flag[i] = true; while (flag[j]); CS; flag[i] = false; (no turn variable). Which statement is correct?
- Two processes each run while (flag[j]); flag[i] = true; CS; flag[i] = false; (check first, then set). Which property fails?