CS FundamentalsModerateGATE CS
Semaphores S = 1, T = 0, U = 0. X: wait(S); print('A'); signal(T). Y: wait(T); print('B'); signal(U). Z: wait(U); print('C'); signal(S). Each process runs its code once, concurrently. Which outputs are possible?
- A. ABC and ACB
- B. Only ABC
- C. Any permutation of A, B, C
- D. ABC, or deadlock if Z runs first
Correct answer: B. Only ABC
Only X can start (S = 1); B needs T from X and C needs U from Y, forcing A, B, C in that order. Z running first just blocks on U until Y signals, so there is no deadlock.
More Operating Systems questions
- Semaphores x = 0 and y = 0. P1: print('A'); signal(x); wait(y); print('B'). P2: print('C'); signal(y); wait(x); print('D'). Which of the…
- Shared int x = 0. Two threads each execute x = x + 1; TWICE, without synchronisation; each statement is a load into a private register, an…
- Shared int x = 1. Thread T1 executes x = x 2; and T2 executes x = x + 3; concurrently with no locking (each is load, compute, store). How…
- Which property does Peterson's algorithm guarantee for two processes, assuming loads and stores are atomic and NOT reordered?
- A test-and-set spinlock: while (TestAndSet(&lock)); / CS / lock = false;. Which requirement of the critical-section problem does it NOT…
- A semaphore S is initialised to 3. The operations wait(S) ×6, signal(S) ×2, wait(S) ×1 are issued in that order by different processes…