CS FundamentalsModerateGATE CS
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). Which statement is correct?
- A. Only 12 is possible
- B. Deadlock is impossible because both semaphores start at 1
- C. Outputs 12 and 21 are possible and deadlock is impossible
- D. Outputs 12 and 21 are possible, and deadlock is also possible
Correct answer: D. Outputs 12 and 21 are possible, and deadlock is also possible
If P1 gets S and P2 gets Q before either takes its second semaphore, each waits for the other: deadlock. If one finishes both waits first, it completes and the other follows, giving 12 or 21.
More Operating Systems questions
- 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…
- Two processes each run flag[i] = true; while (flag[j]); CS; flag[i] = false; (no turn variable). Which statement is correct?