Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
    • Event Scheduling Puzzles
    • Race Condition Puzzles
    • Clocking Block Puzzles
    • Semaphore & Mailbox Puzzles
      • Lock Held Across Blocking Response Wait
      • Bounded Mailbox put Deadlock
      • try_get Busy Spin at Time 0
      • Leaked Semaphore Token on Error Path
      • Two Consumers Waiting on One Mailbox
      • Deadlock-Free Request Loop with try_put/try_get
    • Concurrency & Timing Puzzles: Tricky Q&A
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Semaphore & Mailbox Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Concurrency & Timing Puzzles
  4. Semaphore & Mailbox Puzzles
  5. Two Consumers Waiting on One Mailbox
On this page

    VLSI DV Interview PuzzlesAll 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: Medium · 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

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    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
    endmodule

    Hint

    Mailbox preserves message FIFO, but waiter scheduling fairness is not strict across processes.

    Step-by-step solution

    Diagram
    1) Message order in mailbox is FIFO: 10 then 20.
    2) The two consumers are fork ... join_none children, and the LRM leaves the start order of such children undefined, so even which consumer blocks first in mb.get is undefined.
    3) The LRM also says nothing about the order in which several blocked get calls are served, so which blocked consumer receives 10 is not defined.
    4) A run printing C1 got 10 / C2 got 20 (Verilator 5.048) is legal, and so is C2 got 10 / C1 got 20. The two lines are also at the same time, so their print order is not defined either.

    Answer

    Answer: Data order is FIFO (10 then 20), but the consumer-to-item mapping and the print order are not guaranteed: join_none child start order is undefined and the LRM does not define the service order of several blocked get calls. C2 got 10 / C1 got 20 is a legal outcome.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. Verilator serves the blocked getters in fork order; the LRM does not require that. Forking the consumers in the other order swaps who gets 10, so the mapping is legal either way; only the FIFO data order (10, 20) is guaranteed.

    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)?

    Say it out loud

    The data order is first in, first out, so ten then twenty, but which consumer gets which is not guaranteed. The start order of join_none children is undefined, and the LRM does not define the service order of several blocked gets, so consumer two getting ten is a legal outcome, and so is the print order. The trap is assuming the wake-up order from one tool's run. I would make the test not depend on it, for example with tagged items, and check this on a second simulator.

    Related topics

    • Mailboxes: Typed Pipes with Backpressure

    • Threads and Control: Fork, Disable, Wait, Process

    • Back to Semaphore & Mailbox Puzzles

    • Concurrency & Timing Puzzles section

    Previous

    83 / 293

    Next: Deadlock-Free Request Loop with try_put/try_get

    Up next

    Up nextDeadlock-Free Request Loop with try_put/try_get

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Lock Held Across Blocking Response Wait
    • Bounded Mailbox put Deadlock
    • try_get Busy Spin at Time 0