DescriptionQ028
Q028DVASIC interview problem
Synchronize a one-outstanding producer and consumer
TechniquesDVSystemVerilogMailboxSynchronizationProducer-consumer
DifficultyMedium
TopicTestbench Concurrency
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Implement two finite testbench threads in which the producer may send the next packet only after the consumer acknowledges the previous one. Consumer processing takes 0 through 5 clocks.

Starting declarationSystemVerilog
mailbox #(packet) data_mb = new(1);
mailbox #(bit) ack_mb = new(1);Example input and output
Use this case to check your interpretationInput
consumer delay = 5 clocks for every packetOutput
packet IDs 0 through 9 are received once in order, with at most one packet outstandingExplanation
The producer blocks on ack_mb.get() after every put, so it cannot enqueue the next packet until the consumer completes the prior one.
02
Requirements (4)
- Block the producer after each data put until one acknowledgment is received.
- Have the consumer receive one packet, wait 0 through 5 clocks, and send exactly one acknowledgment.
- Transmit packet IDs 0 through 9 exactly once and wait for both threads to finish.
- Use persistent mailbox tokens rather than a bare event whose trigger could be missed.
