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
  • UVM Testbench Puzzles25
    • UVM Phases and Objections
    • Factory and config_db
    • Sequences and Sequencers
      • try_next_item Loop That Never Lets Time Pass
      • When finish_item Returns
      • lock Versus grab Ordering
      • Inline Constraint That Constrains Nothing
      • Virtual Sequence Started With null
      • Default Sequence Ends at Time Zero
    • Analysis, Scoreboards and RAL
    • UVM Testbench Puzzles: Tricky Q&A
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Sequences and Sequencers
  1. Topics
  2. DV Interview Puzzles
  3. UVM Testbench Puzzles
  4. Sequences and Sequencers
  5. lock Versus grab Ordering
On this page

    VLSI DV Interview PuzzlesAll levels

    lock Versus grab Ordering

    UVM 1.2. Sequence A already holds the sequencer by lock() (granted). While A runs, B calls lock() and then C calls grab() on the same sequencer. A then calls unlock(). Which sequence gets exclusive use next, and which after that?

    Puzzle

    Difficulty: Medium · Puzzle 3 of 6 · Topic: Sequences and Sequencers

    UVM 1.2. Sequence A already holds the sequencer by lock() (granted). While A runs, B calls lock() and then C calls grab() on the same sequencer. A then calls unlock(). Which sequence gets exclusive use next, and which after that?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // A (running, lock already granted)
    lock(m_sequencer);
    ...
    unlock(m_sequencer);
    
    // B, arriving later
    lock(m_sequencer);
    ...
    unlock(m_sequencer);
    
    // C, arriving after B
    grab(m_sequencer);
    ...
    ungrab(m_sequencer);

    Hint

    A grab is a lock that is allowed to jump the queue of waiting requests, but not to take the sequencer away from the current owner.

    Step-by-step solution

    Diagram
    1) lock requests wait their turn in the arbitration queue: B is queued at the back.
    2) A grab request is inserted at the front of that queue, ahead of waiting lock requests such as B.
    3) Neither B nor C can take the sequencer away from A, which owns it until it unlocks.
    4) After A's unlock, C (grab) is granted before B (lock); after C's ungrab, B is granted. Order: C, then B.

    Answer

    Answer: C gets the sequencer first (grab jumps ahead of the waiting lock), then B.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. Hand-written model of the documented UVM 1.2 behaviour in plain SystemVerilog (Verilator), not the UVM library: an arbitration queue where lock does push_back and grab does push_front, as documented for uvm_sequencer_base.

    Why candidates get it wrong

    grab does not pre-empt a lock that has already been granted: it only wins against requests still waiting; and a sequence that holds a lock blocks everyone else's items, including ones its own children would need if it forgets to unlock.

    Interviewer follow-up

    What do you do when a sequence must always run exclusively, e.g. a reset sequence, even if another lock is waiting? Model answer: have it grab the sequencer (so it goes ahead of all waiting requests) and ungrab in the same body on every exit path, preferably a single exit, or use a sequencer-wide mechanism such as an arbitration mode with priorities; never rely on lock for urgency.

    Related topics

    • Back to Sequences and Sequencers

    • UVM Testbench Puzzles section

    Previous

    225 / 293

    Next: Inline Constraint That Constrains Nothing

    Up next

    Up nextInline Constraint That Constrains Nothing

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • try_next_item Loop That Never Lets Time Pass
    • Virtual Sequence Started With null
    • Default Sequence Ends at Time Zero