DescriptionQ115
Q115DVASIC interview problem
Detect a deadlock in a wait graph
TechniquesGraphDeadlockThree-color DFS
DifficultyMedium
TopicVerification Utilities
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Maintain runtime wait dependencies among agents or queues. A directed edge from A to B means A is waiting on B. Return whether any dependency cycle exists.

Class declarationSystemVerilog
class DeadlockDetector;
function void wait_on(int from, int to);
function void clear_wait(int from);
function bit has_deadlock();
endclassExample input and output
Use this case to check your interpretationInput
add waits 1->2 and 2->3; query; add 3->1; queryOutput
no deadlock, then deadlock detectedExplanation
The first graph is an acyclic chain; the final edge closes the directed cycle 1->2->3->1.
02
Requirements (4)
- Add a directed dependency and create target-only nodes as needed.
- Clear every outgoing dependency for one agent.
- Detect a cycle anywhere in a disconnected graph.
- Do not report a converging acyclic dependency chain as a deadlock.
