CS FundamentalsHardGATE CS
Semaphores s = 2, t = 0. Process X runs `repeat 2 times { wait(s); print('A'); signal(t); }` and Y runs `repeat 2 times { wait(t); print('B'); signal(s); }` concurrently. Which outputs are possible?
- A. ABAB only
- B. AABB only
- C. AABB and ABAB
- D. ABAB, AABB and ABBA
Correct answer: C. AABB and ABAB
With s = 2, X can print both A's before Y runs, or Y can print B after the first A. B can never come first and can never outrun the A's (t counts A's printed). Possible: AABB, ABAB.
More Operating Systems questions
- Shared x = 0. Three threads each execute x = x + 1; once (load, add, store; no locking). What is the set of possible final values?
- Shared x = 0. Thread A executes x = x + 1; twice and thread B executes x = x - 1; twice, with no synchronisation (each statement is load…
- 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…
- 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)…