Detect a Deadlock From a Trace of Lock Events
Last updated: November 29, 2026
Quick Overview
Given an ordered trace of lock acquire, release, and blocked-wait events from threads in a server, determine whether the threads are deadlocked and return the cycle.
0
0
0 solved
Given an ordered trace of lock acquire, release, and blocked-wait events from threads in a server, determine whether the threads are deadlocked and return the cycle.
Debugging hung servers is real work at Google, where thread dumps show who holds and who waits on which mutex. This question blends graph reasoning with concurrency knowledge, and interviewers check that you build the wait-for graph rather than guessing.
What the Interviewer Expects
- Builds lock-to-holder and thread-to-awaited-lock maps
- Constructs the wait-for graph between threads
- Detects a cycle and returns its members
- Handles self-deadlock on non-reentrant locks
- Discusses prevention via lock ordering
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you extend this to read-write locks with many holders?
- How do you prevent the deadlock in the code that produced it?
- How would you detect it live without a full trace?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Events are
(thread, action, lock), action in acquire, release, wait. Wait means currently blocked requesting the lock. - Locks are exclusive. Return the list of threads in a cycle, or None....
High-Level Design
Replay events to get the final state: who holds each lock and which lock each blocked thread wants. Each blocked thread has one outgoing edge to the holder of its awaited lock. With out-degree at most...