CS FundamentalsHardGATE CS
Semaphore s = 0. P1: print('a'); signal(s); print('b'). P2: wait(s); print('c'); print('d'). How many different output strings are possible?
- A. 4
- B. 3
- C. 2
- D. 6
Correct answer: B. 3
'a' must come first; then 'b' may land before 'c', between 'c' and 'd', or after 'd': abcd, acbd, acdb.
More Operating Systems questions
- 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…
- Strict alternation uses a shared turn variable: P0: while (turn != 0); CS; turn = 1; P1: while (turn != 1); CS; turn = 0;. P0 wants to…