CS FundamentalsHardGATE CS (PYQ pattern)
A 2-slot bounded buffer uses mutex = 1, empty = 2, full = 0. Two producers each insert 2 items with the (buggy) code wait(mutex); wait(empty); insert, print p; signal(mutex); signal(full). One consumer removes 3 items with the correct code wait(full); wait(mutex); remove, print c; signal(mutex); signal(empty). All three start together. Which statement is correct?
- A. No deadlock is possible, because the consumer still waits on full before mutex
- B. Deadlock is possible, and every deadlock occurs with the buffer full
- C. Deadlock is possible only when the buffer is empty
- D. Deadlock is possible only after all 3 items have been consumed
Correct answer: B. Deadlock is possible, and every deadlock occurs with the buffer full
A producer that holds mutex and blocks on empty (buffer full) stops the consumer, which needs mutex to remove an item. Exhaustive exploration finds deadlocks after outputs pp, ppcp and pcpp: each has 2 items in the buffer and a producer holding mutex. With the buffer not full, wait(empty) succeeds at once, so no other deadlock exists. 8 complete outputs remain possible as well.
More Operating Systems questions
- SRTF (preemptive shortest remaining time first; ties go to the earlier arrival) is used for processes (arrival, burst) in ms: P1 (0, 9)…
- Preemptive priority scheduling (a smaller number means higher priority; equal priorities are served by earlier arrival, without time…
- A lottery scheduler holds a fresh draw every quantum. Process A has 100 tickets, B has 200 and C has 300 (every process always stays…
- Rate-monotonic scheduling (preemptive, deadline = period, all tasks released together at t = 0) is used for T1 (C = 1, period 4), T2 (C =…
- A 3-level paging system has a TLB (1 ns, hit ratio 95%) and a cache in front of memory (10 ns hit time, 90% hit ratio, and a miss costs 10…
- Segment table (base, limit in bytes): seg 0 = (1000, 400), seg 1 = (2400, 100), seg 2 = (3000, 250), seg 4 = (500, 60); segment 3 is not…