Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Synchronize a one-outstanding producer and consumer

Q161·Free·Design Verification

Synchronize a one-outstanding producer and consumer

Difficulty
Medium
Topic
Testbench Concurrency
Language
SV
Interview prompt

Question

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.

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.
Candidate starting point

Implementation scaffold

module producer_consumer(input logic clk);
  class packet;
    int unsigned id;
    function new(int unsigned id); this.id=id; endfunction
  endclass
  mailbox #(packet) data_mb = new(1);
  mailbox #(bit) ack_mb = new(1);
  task automatic producer();
    // TODO: send IDs 0 through 9, waiting for each acknowledgment.
  endtask
  task automatic consumer();
    // TODO: process exactly 10 packets and acknowledge each.
  endtask
  initial begin
    // TODO: run both threads and wait for completion.
  end
endmodule
Reviewed example

Trace 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.
Exact question handoffPractice Q161

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Communication and Synchronization

Review mailboxes, semaphores, events, capacity, ownership, and wakeup behavior.

  • Testbench Concurrency
  • SystemVerilog
  • Mailbox
  • Synchronization
Communication and Synchronization →
Continue practicing

Related questions

Q669 · Verification UtilitiesMailbox peek and blocking putMediumP→Q199 · Computer ArchitectureBuild a bounded one-producer, one-consumer queueEasy→Q997 · VerificationFix event-loss and shared-state monitor bugsMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi