Difficulty: Easy · Puzzle 3 of 6 · Topic: Semaphore & Mailbox Puzzles
No deadlock occurs, but simulation appears frozen at t=0. Explain root cause and proper fix.
module tb;
mailbox #(int) mb = new();
int item;
initial begin
forever begin
if (!mb.try_get(item)) begin
// no delay, no event wait
end
end
end
endmoduleA non-blocking API still needs timing control in polling loops.
1) try_get returns immediately when mailbox empty.
2) Loop has no blocking statement or delay.
3) Process consumes simulator cycles in same time slot, often stuck at t=0.
4) Add blocking get, wait event, or small delay/backoff in empty case.Answer: This is a zero-delay busy spin, not a protocol deadlock. Add wait/delay or switch to blocking get.
Non-blocking call does not imply low-overhead loop by itself.
What backoff policy would you use to avoid both starvation and performance collapse?