VLSI DV Interview Puzzles · All levels
Two Consumers Waiting on One Mailbox
Producer sends two items after both consumers are blocked on get. Is consumer wake-up order guaranteed?
Puzzle
Difficulty: Hard · Puzzle 5 of 6 · Topic: Semaphore & Mailbox Puzzles
Producer sends two items after both consumers are blocked on get. Is consumer wake-up order guaranteed?
Code
module tb;
mailbox #(int) mb = new();
task consumer(string name);
int v;
mb.get(v);
$display("[%0t] %s got %0d", $time, name, v);
endtask
initial fork
consumer("C1");
consumer("C2");
join_none
initial begin
#5 mb.put(10);
#0 mb.put(20);
#1 $finish;
end
endmoduleHint
Mailbox preserves message FIFO, but waiter scheduling fairness is not strict across processes.
Step-by-step solution
1) Message order in mailbox is FIFO: 10 then 20.
2) Which blocked consumer gets first wake-up is not a robust fairness contract to rely on.
3) One run may print C1->10, C2->20; another may swap consumer names with same data order.Answer
Answer: Data order is FIFO (10 then 20), but consumer-to-item mapping is not a portability-safe fairness guarantee.
Why candidates get it wrong
Assuming blocked getter wake-up order is deterministic across all tools can break regressions.
Interviewer follow-up
How would you enforce deterministic ownership (per-agent mailbox or tagged routing)?