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.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

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
deadlock detection
wait-for graph
cycle detection
lock ordering
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported