CS FundamentalsVery hardGATE CS
Semaphores a = b = c = 0. P1: print A; signal(a); wait(b); wait(c); print X. P2: print B; signal(b); signal(b); wait(a); print Y. P3: print C; signal(c); wait(b); print Z. Which of these outputs is possible: ABCXYZ, BAYCZX, CBZAXY, ABXCYZ?
- A. All four
- B. ABCXYZ, BAYCZX, CBZAXY only
- C. ABCXYZ only
- D. ABCXYZ, BAYCZX and ABXCYZ only
Correct answer: B. ABCXYZ, BAYCZX, CBZAXY only
X needs b (after B) and c (after C); Y needs a (after A); Z needs b (after B). ABXCYZ prints X before C, which is impossible. The others respect every dependency, as an exhaustive interleaving check confirms.
More Operating Systems questions
- Semaphore s = 0. P1: print('a'); signal(s); print('b'). P2: wait(s); print('c'); print('d'). How many different output strings are possible?
- Binary semaphores S = Q = 1. P1: wait(S); wait(Q); print 1; signal(Q); signal(S). P2: wait(Q); wait(S); print 2; signal(S); signal(Q)…
- A producer runs repeat 3 { wait(empty); print('p'); signal(full); } and a consumer runs repeat 3 { wait(full); print('c'); signal(empty)…
- 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…