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
  • 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
      • fork...join_none Thread Leak
      • Semaphore Token Leak on Error Path
      • Mailbox Consumer Blocks Forever
      • Lock Inversion with Two Semaphores
      • Child Sequence Raises Objection but Never Drops
    • Scoreboard Puzzles: Mismatch or Ordering Bug?
    • Real Interview Rounds: End-to-End Debug Walkthrough
    • Scenario & Debug Puzzles: Tricky Q&A
  • Interview Prep: Puzzle Rounds5
  • 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. Lock Inversion with Two Semaphores

VLSI DV Interview Puzzles · All levels

Lock Inversion with Two Semaphores

Two agents deadlock rarely under high parallel load. The failure disappears if either agent runs alone.

On this page

    Puzzle

    Difficulty: Hard · Puzzle 5 of 6 · Topic: Deadlock Scenario Puzzles: Objection and Phase Stalls

    Two agents deadlock rarely under high parallel load. The failure disappears if either agent runs alone.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    semaphore cfg_sem = new(1);
    semaphore bus_sem = new(1);
    
    task agent_a();
      cfg_sem.get(1);
      #1ns;
      bus_sem.get(1);
      bus_sem.put(1);
      cfg_sem.put(1);
    endtask
    
    task agent_b();
      bus_sem.get(1);
      #1ns;
      cfg_sem.get(1);
      cfg_sem.put(1);
      bus_sem.put(1);
    endtask

    Hint

    Classic AB-BA acquisition ordering bug.

    Step-by-step solution

    Diagram
    1) Capture semaphore acquisition timeline from both agents on failing seed.
    2) Confirm agent_a holds cfg_sem waiting bus_sem while agent_b holds bus_sem waiting cfg_sem.
    3) Enforce one global lock order across all users (for example cfg then bus everywhere).
    4) Optionally merge locks if independent parallelism is not needed.
    5) Add lock-order assertions in debug builds.

    Answer

    Answer: Bug: lock inversion causes circular wait (AB-BA deadlock). Fix: enforce consistent semaphore acquisition order across all threads.

    Why candidates get it wrong

    Random seed changes only shift timing; they do not remove the structural deadlock risk.

    Interviewer follow-up

    If lock ordering cannot be unified, what timeout/retry strategy would you choose and why?

    Related topics

    • Back to Deadlock Scenario Puzzles: Objection and Phase Stalls

    • Scenario & Debug Puzzles section

    Previous

    190 / 210

    Next: Child Sequence Raises Objection but Never Drops

    Up next

    Up nextChild Sequence Raises Objection but Never Drops

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Early Return Leaves Objection Raised
    • fork...join_none Thread Leak
    • Semaphore Token Leak on Error Path