CS FundamentalsModerateGATE CS (PYQ pattern)
A counting semaphore S starts at 3 and is implemented so that wait() decrements S and blocks the caller if S becomes negative, while signal() increments S and wakes one blocked thread if S <= 0 afterwards. Threads T1 to T6 each execute wait(S) once and enter the work section when wait returns. Later T1 and T2 leave with signal(S). What are S, the number of blocked threads and the number inside the work section?
- A. S = -1, 1 blocked, 5 inside
- B. S = 0, 0 blocked, 4 inside
- C. S = -1, 1 blocked, 3 inside
- D. S = 1, 0 blocked, 2 inside
Correct answer: C. S = -1, 1 blocked, 3 inside
Six waits take S from 3 to -3: three threads enter, three block. Each signal raises S (-2, then -1) and wakes one blocked thread. Now S = -1, so 1 thread still waits; inside = 6 started - 2 left - 1 blocked = 3, which is the semaphore's limit. 5 inside forgets that T1 and T2 left.
More Operating Systems questions
- A 16-core machine must unmap a page that all cores have in their TLBs. The initiating core sends an inter-processor interrupt to each of…
- Two periodic tasks with deadline = period and zero release offset: T1 (C=2, P=5) and T2 (C=4, P=7). Total utilisation is 2/5 + 4/7 ≈…
- Three periodic tasks (deadline = period, all released at t=0) are scheduled by preemptive rate-monotonic scheduling: T1 (C=2, P=5), T2…
- Two processes use shared variables flag[2] (initially 0) and turn. Process i (j = 1−i) runs: V1: flag[i]=1; turn=j; while(flag[j] &&…
- Binary semaphore m is initialised to 1. P1: P(m); print A; V(m); print B. P2: P(m); print C; V(m); print D. P3: P(m); print E; V(m). All…
- Priority-based preemptive scheduling with L (low), M (medium), H (high). L arrives at t=0 and needs 10 units; at t=1 L locks a mutex and…