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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • 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
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Semaphore & Mailbox Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Concurrency & Timing Puzzles
  4. Semaphore & Mailbox Puzzles
  5. Leaked Semaphore Token on Error Path

VLSI DV Interview Puzzles · All levels

Leaked Semaphore Token on Error Path

Predict output and explain why worker B times out even though worker A exits quickly.

On this page

    Puzzle

    Difficulty: Medium · Puzzle 4 of 6 · Topic: Semaphore & Mailbox Puzzles

    Predict output and explain why worker B times out even though worker A exits quickly.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    module tb;
      semaphore sem = new(1);
    
      task worker_a();
        sem.get(1);
        $display("[%0t] A got token", $time);
        if (1) return; // missing sem.put(1)
      endtask
    
      task worker_b();
        int ok;
        #10;
        ok = sem.try_get(1);
        $display("[%0t] B try_get=%0d", $time, ok);
      endtask
    
      initial fork
        worker_a();
        worker_b();
      join
    endmodule

    Hint

    Resource leaks are deadlocks in slow motion.

    Step-by-step solution

    Diagram
    1) A gets token at t=0 and exits without put.
    2) Token count stays 0 permanently.
    3) B tries at t=10; try_get returns 0.
    4) No one can acquire semaphore afterward.

    Answer

    Answer: Prints [0] A got token and [10] B try_get=0. Missing put leaks token and blocks all future owners.

    Why candidates get it wrong

    Returning early without finally-style cleanup is a frequent infrastructure bug.

    Interviewer follow-up

    How would you enforce token release using begin...end with automatic cleanup patterns?

    Related topics

    • Back to Semaphore & Mailbox Puzzles

    • Concurrency & Timing Puzzles section

    Previous

    76 / 210

    Next: Two Consumers Waiting on One Mailbox

    Up next

    Up nextTwo Consumers Waiting on One Mailbox

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Lock Held Across Blocking Response Wait
    • Bounded Mailbox put Deadlock
    • Deadlock-Free Request Loop with try_put/try_get