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
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
    • Testbench Debug Puzzles: Why Did the Test Hang?
    • Deadlock Scenario Puzzles: Objection and Phase Stalls
      • Early Return Leaves Objection Raised
      • Background Poller Keeps Running After Traffic Ends
      • Semaphore Token Leak on Error Path
      • join_any Ends the Task with the Mailbox Full
      • Lock Inversion with Two Semaphores
      • disable fork Kills the Thread That Owned the Drop
    • Scoreboard Puzzles: Mismatch or Ordering Bug?
    • Real Interview Rounds: End-to-End Debug Walkthrough
    • Scenario & Debug Puzzles: Tricky Q&A
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Deadlock Scenario Puzzles: Objection and Phase Stalls
  1. Topics
  2. DV Interview Puzzles
  3. Scenario & Debug Puzzles
  4. Deadlock Scenario Puzzles: Objection and Phase Stalls
  5. Semaphore Token Leak on Error Path
On this page

    VLSI DV Interview PuzzlesAll levels

    Semaphore Token Leak on Error Path

    Two parallel sequences share one bus lock and eventually freeze under error injection. Only failing seeds hit the deadlock.

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: Deadlock Scenario Puzzles: Objection and Phase Stalls

    Two parallel sequences share one bus lock and eventually freeze under error injection. Only failing seeds hit the deadlock.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    semaphore bus_sem = new(1);
    
    task send_req(my_item req);
      bus_sem.get(1);
      if (req.timeout_fault) begin
        \`uvm_error("DRV", "timeout")
        return; // bug: token never returned
      end
      drive_req(req);
      bus_sem.put(1);
    endtask

    Hint

    Resource ownership must be balanced even in exceptional exits.

    Step-by-step solution

    Diagram
    1) Add semaphore occupancy debug counters around get/put.
    2) Reproduce with timeout_fault and observe token count never returns.
    3) Refactor with cleanup block so put executes for all post-get exits.
    4) Consider try/finally-style coding pattern for shared resources.
    5) Add assertion: semaphore token count reaches initial value at phase end.

    Answer

    Answer: Bug: return on timeout path leaks semaphore token, blocking all later requests. Fix: always put token after successful get, regardless of error path.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. Plain-SV semaphore model of the leaked token: the second request blocks forever until the error path also does put.

    Why candidates get it wrong

    People suspect simulator scheduling; this is deterministic resource leak.

    Interviewer follow-up

    Would a mailbox-based arbitration model be safer here than manual semaphores? Model answer: No: a one-slot mailbox used as a token has the same leak if the return path skips the put. The real fix is structural: a wrapper task that does get, calls the body, and put in one place so every path (including error returns) executes the put. Assert the token count equals the initial value at end of phase.

    Say it out loud

    First I check whether the later requests are all blocked on the same semaphore, because that points at a resource that was never returned. The root cause is that the return on the timeout path leaks the semaphore token, so every later request waits forever. This is a deterministic resource leak, not simulator scheduling. I confirm it by counting gets against puts, and the fix is to put the token back after every successful get, whatever the error path.

    Related topics

    • Credit and Token Loss

    • Who Is Waiting for Whom

    • Back to Deadlock Scenario Puzzles: Objection and Phase Stalls

    • Scenario & Debug Puzzles section

    Previous

    194 / 293

    Next: join_any Ends the Task with the Mailbox Full

    Up next

    Up nextjoin_any Ends the Task with the Mailbox Full

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Early Return Leaves Objection Raised
    • Lock Inversion with Two Semaphores
    • disable fork Kills the Thread That Owned the Drop