CS FundamentalsHardGATE CS
A bounded-buffer monitor with Mesa-style signalling uses: get() { if (count == 0) wait(notEmpty); item = buf[out]; count--; ... } and put() calls signal(notEmpty) after storing an item. Two consumers and one producer share it. Which statement is correct?
- A. The code is safe because signal always wakes exactly one waiter immediately
- B. Underflow is possible because a woken consumer may run after another consumer has taken the item; the wait must sit in a while loop
- C. Underflow is impossible, but two consumers may deadlock
- D. Replacing signal with broadcast alone makes the code safe
Correct answer: B. Underflow is possible because a woken consumer may run after another consumer has taken the item; the wait must sit in a while loop
In Mesa semantics the signalled thread is only made ready; before it runs, another consumer entering get() can take the item, leaving count == 0. The woken thread then decrements below zero. Rechecking the condition in a while loop fixes it, while broadcast with an if still fails.
More Operating Systems questions
- A three-level feedback queue: Q0 (quantum 2), Q1 (quantum 4), Q2 (FCFS). New processes join Q0 and preempt lower queues; a process that…
- The reference string of a process is 1 2 1 3 4 4 5 2 3 2 2 6 7 7 6 1. Using a working-set window of the last 5 references (including the…
- The page reference string is 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6 and 3 frames are available (initially empty). The numbers of page…
- Five processes arrive with burst times: P1 (arrival 0, burst 8), P2 (1, 4), P3 (2, 9), P4 (3, 5), P5 (4, 2). Under preemptive SJF (SRTF)…
- A system has 3 resource types and processes P0-P3. Allocation: P0 (1,0,1), P1 (2,1,0), P2 (1,1,1), P3 (0,1,2). Maximum: P0 (3,2,2), P1…
- A paged system has a TLB lookup time of 10 ns, a TLB hit ratio of 90% and a memory access time of 100 ns. A TLB miss needs one extra…