CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ
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. Which outputs are possible?
- A. ABCD and ABDC
- B. ABCD only
- C. ABCD, ABDC and ACBD
- D. ABDC only
Correct answer: A. ABCD and ABDC
A must precede B (x), and B precedes both C and D because T2 signals y and z only after printing B. After that, T1's D and T3's C can come in either order.
More Operating Systems questions
- 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…
- A buddy allocator manages 1024 KB starting at address 0 and always uses the lowest-addressed free block of the needed size. Requests: A =…