Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Synchronize a one-outstanding producer and consumer

Hardware interview practice

Synchronize a one-outstanding producer and consumer

MediumTestbench ConcurrencySystemVerilog

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.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Producer-consumer sequence using depth-one data and acknowledgement mailboxes to keep at most one packet outstanding.
A persistent acknowledgement token releases the producer only after the consumer finishes the current packet.
Starting point

Question code

mailbox #(packet) data_mb = new(1);
mailbox #(bit)    ack_mb  = new(1);
Reviewed example

Work through one case

Input
consumer delay = 5 clocks for every packet
Expected output
packet IDs 0 through 9 are received once in order, with at most one packet outstanding

The producer blocks on ack_mb.get() after every put, so it cannot enqueue the next packet until the consumer completes the prior one.

What to cover

Requirements

  1. Block the producer after each data put until one acknowledgment is received.
  2. Have the consumer receive one packet, wait 0 through 5 clocks, and send exactly one acknowledgment.
  3. Transmit packet IDs 0 through 9 exactly once and wait for both threads to finish.
  4. Use persistent mailbox tokens rather than a bare event whose trigger could be missed.
asic.fyi · Learn silicon end to end.info@asic.fyi