VLSI DV Interview Puzzles · All 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: Medium · 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
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);
endtaskHint
Resource ownership must be balanced even in exceptional exits.
Step-by-step solution
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.
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?