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. Lock Held Across Blocking Response Wait

VLSI DV Interview Puzzles · All levels

Lock Held Across Blocking Response Wait

Find the deadlock cycle and propose the minimal fix without changing protocol intent.

On this page

    Puzzle

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

    Find the deadlock cycle and propose the minimal fix without changing protocol intent.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    module tb;
      semaphore lock = new(1);
      mailbox #(int) req_mb = new();
      mailbox #(int) rsp_mb = new();
    
      task producer();
        int rsp;
        lock.get(1);
        req_mb.put(7);
        rsp_mb.get(rsp);
        lock.put(1);
      endtask
    
      task consumer();
        int req;
        lock.get(1);
        req_mb.get(req);
        rsp_mb.put(req + 1);
        lock.put(1);
      endtask
    
      initial fork
        producer();
        consumer();
      join_none
    endmodule

    Hint

    Producer blocks while still owning token that consumer needs.

    Step-by-step solution

    Diagram
    1) Producer acquires lock and sends request.
    2) Producer blocks on rsp_mb.get while holding lock.
    3) Consumer cannot acquire lock, so it cannot read request or send response.
    4) Circular wait causes deadlock.
    5) Fix: release lock before blocking mailbox call or reorder lock ownership.

    Answer

    Answer: Deadlock is lock -> rsp_mb.get -> lock cycle. Minimal fix: never hold semaphore across blocking mailbox operations.

    Why candidates get it wrong

    Mailbox get is still a blocking wait edge in deadlock analysis, not just 'message passing'.

    Interviewer follow-up

    Show a lock-free request/response pattern using mailbox-only synchronization.

    Related topics

    • Back to Semaphore & Mailbox Puzzles

    • Concurrency & Timing Puzzles section

    Previous

    73 / 210

    Next: Bounded Mailbox put Deadlock

    Up next

    Up nextBounded Mailbox put Deadlock

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • try_get Busy Spin at Time 0
    • Leaked Semaphore Token on Error Path
    • Two Consumers Waiting on One Mailbox