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. try_get Busy Spin at Time 0
On this page

    VLSI DV Interview PuzzlesAll levels

    try_get Busy Spin at Time 0

    No deadlock occurs, but simulation appears frozen at t=0. Explain root cause and proper fix.

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: Semaphore & Mailbox Puzzles

    No deadlock occurs, but simulation appears frozen at t=0. Explain root cause and proper fix.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    module tb;
      mailbox #(int) mb = new();
      int item;
      initial begin
        forever begin
          if (!mb.try_get(item)) begin
            // no delay, no event wait
          end
        end
      end
    endmodule

    Hint

    A non-blocking API still needs timing control in polling loops.

    Step-by-step solution

    Diagram
    1) try_get returns immediately when mailbox empty.
    2) Loop has no blocking statement or delay.
    3) The loop never suspends, so the process never gives control back to the scheduler: simulation time can never advance past t=0 and no other process is guaranteed to run. It is always stuck, not 'often' (Verilator hung until killed; even a #5 print in another initial never appeared).
    4) This is a zero-delay livelock, not a deadlock: the process keeps running, but time is frozen.
    5) Fix: use a blocking mb.get(item), or poll with #1 / @(posedge clk), or wait on an event raised by the producer.

    Answer

    Answer: This is a zero-delay busy spin (livelock), not a protocol deadlock: the loop has no timing control, so time never advances past t=0 and other processes do not get to run. Switch to a blocking mb.get, or poll with #1 or @(posedge clk).

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. A try_get loop with no timing control keeps time at 0 while it spins (bounded here so the run ends). Adding #1 to the poll lets time advance and the item is picked up at t=3.

    Why candidates get it wrong

    Non-blocking call does not imply low-overhead loop by itself.

    Interviewer follow-up

    What backoff policy would you use to avoid both starvation and performance collapse? Model answer: prefer a blocking get so no polling is needed. If polling is required, use a fixed small poll such as #1 or @(posedge clk), or exponential backoff capped at a few clocks (1, 2, 4, then stay at 4) that resets after a successful get, so latency stays bounded and the simulator is not woken every time step.

    Say it out loud

    This is not a deadlock, it is a zero-delay livelock. The try_get returns at once on an empty mailbox and the loop has no timing control, so it never gives the scheduler a chance, time never leaves zero and other processes never run. It always hangs, not sometimes. The trap is believing a non-blocking call makes a cheap loop. The fix is a blocking get, or poll with a delay or a clock edge, or wait on an event, and I would check there is no other tight loop.

    Related topics

    • Mailboxes: Typed Pipes with Backpressure

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

    • Back to Semaphore & Mailbox Puzzles

    • Concurrency & Timing Puzzles section

    Previous

    81 / 293

    Next: Leaked Semaphore Token on Error Path

    Up next

    Up nextLeaked Semaphore Token on Error Path

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Lock Held Across Blocking Response Wait
    • Two Consumers Waiting on One Mailbox
    • Deadlock-Free Request Loop with try_put/try_get