CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ
Semaphores s = 2 and t = 0. T1 runs twice: wait(s); print('a'); signal(t). T2 runs twice: wait(t); print('b'); signal(s). Which outputs are possible?
- A. abab only
- B. aabb only
- C. abab and aabb
- D. abab, aabb and abba
Correct answer: C. abab and aabb
Since s starts at 2, T1 may print both a's before T2 runs (aabb), or T2 may print b in between (abab). A b always needs a preceding a (t starts at 0), so abba and any output starting with b are impossible.
More Operating Systems questions
- Semaphores x = y = z = 0. T1: print A; signal(x); wait(y); print D. T2: wait(x); print B; signal(y); signal(z). T3: wait(z); print C…
- Shared x = 1. Three threads run once each, with no locking: T1 does x = x + 2, T2 does x = x 3, T3 does x = x − 1. Each statement is a…
- Shared x = 1. Thread A executes x = x + 1 twice; thread B executes x = x 2 once; each statement is a separate load and store and there is…
- References at times 1 to 12 are 1, 3, 2, 3, 4, 4, 1, 5, 2, 5, 5, 3. With working-set window Δ = 5 (the last 5 references, including the…
- Three processes share one resource type with identical instances. P1 may need at most 3 instances, P2 at most 4 and P3 at most 5, and each…
- Free holes (in order) are 150, 400, 220, 350 and 500 KB. Requests of 210, 380, 140 and 330 KB arrive in that order. Which placement…