CS FundamentalsHardGATE CS
A bounded-buffer producer is written as wait(mutex); wait(empty); add item; signal(mutex); signal(full); while the consumer is the usual wait(full); wait(mutex); remove; signal(mutex); signal(empty). What can go wrong?
- A. Two producers may write the same slot
- B. Nothing; the order of wait calls does not matter
- C. The consumer may remove from an empty buffer
- D. When the buffer is full, the producer sleeps on empty while holding mutex, and the consumer blocks on mutex: deadlock
Correct answer: D. When the buffer is full, the producer sleeps on empty while holding mutex, and the consumer blocks on mutex: deadlock
wait(empty) blocks only when the buffer is full, and the producer then holds mutex while sleeping. The consumer that would free a slot needs mutex first, so neither can proceed. Counting waits must come before taking the mutex.
More Operating Systems questions
- Which statement about Belady's anomaly is correct?
- A machine has 32 GB of physical memory, 4 KB frames and an inverted page table with 8-byte entries. How big is the table, and why is a…
- Which statements are correct? 1. A child that has exited but whose parent has not called wait() is a zombie. 2. A zombie still holds its…
- The reference string at times 1–12 is 3, 5, 3, 8, 2, 5, 5, 9, 3, 9, 2, 2. With a working-set window Δ = 5 references, what are the…
- A device delivers data at 2 MB/s. Per-byte interrupts would cost 5 µs each; instead DMA moves 4 KB blocks and raises one interrupt per…
- A TLB has 64 entries. A program randomly touches a 100 MB data set. What is the TLB reach with 4 KB pages and with 2 MB huge pages, and…