Skip to content
Skills Library
Programming · Analysis

deadlock-analysis

/deadlock-analysis

Find why threads are stuck forever by dumping their state and building the wait-for graph that reveals the lock cycle. Use when a program hangs with no progress and no crash, or throughput drops to zero while CPU sits idle.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Find why threads are stuck forever by dumping their state and building the wait-for graph that reveals the lock cycle. Use when a program hangs with no progress and no crash, or throughput drops to zero while CPU sits idle.

Original author description

Find why threads are stuck forever by dumping their state and building the wait-for graph that reveals the lock cycle. Use when a program hangs with no progress and no crash, or throughput drops to zero while CPU sits idle.

How it works

  1. Method
  2. Signals
  3. Boundaries
Original SKILL.md headings · 53 lines, 472 words
SKILL.md preview
---
name: deadlock-analysis
description: Find why threads are stuck forever by dumping their state and building the wait-for graph that reveals the lock cycle. Use when a program hangs with no progress and no crash, or throughput drops to zero while CPU sits idle.
---

# Deadlock analysis

A deadlock is a cycle of waiting: thread A holds lock 1 and wants lock 2
while thread B holds lock 2 and wants lock 1, and neither will ever move.
The process is not crashed, it is frozen, which fools you into looking for a
slow operation instead of a stuck one. The cycle is always visible in a
thread dump if you know how to read the waits.

## Method

1. **Confirm it is a deadlock, not slowness.** Idle CPU with zero progress
   for minutes points at blocking, not computation. A busy CPU spinning
   forever is a livelock or infinite loop, a different bug. Check that
   threads are parked in a wait state, not running hot.
2. **Capture a thread dump at the moment of the hang.** `jstack <pid>` or
   `kill -3` on the JVM, `py-spy dump --pid` for Python, `dlv` or `SIGQUIT`
   for Go (which prints all goroutine stacks), `gdb -p <pid>` then `thread
   apply all bt` for native. Take two dumps a few seconds apart: if the
   stacks are identical, nothing is moving.
3. **Read who holds what and who waits for what.** A good dump names it
   directly: the JVM prints "Found one Java-level deadlock" with the lock
   ids, "waiting to lock <0x...>" versus "locked <0x...>". For each blocked
   thread, write down the lock it holds and the lock it wants.
4. **Draw the wait-for graph and find the cycle.** Nodes are threads, an
   edge runs from a thread to the thread holding the lock it waits on. A
   cycle in that graph is the deadlock, and the locks on the cycle are the
   ones acquired in conflicting order. Two locks is the common case; the
   graph scales to more.
5. **Fix with a global lock ordering.** Pick a total order for the locks on
   the cycle (by address, by name, by a fixed rank) and make every code path
   acquire them in that order. If ordering is impractical, use a single
   coarser lock, a `tryLock` with timeout and backoff, or lock-free
   structures. Consistent order breaks every cycle by construction.
6. **Prove it under contention.** Run the path that hung under many threads
   for an extended loop. A deadlock that reproduced in minutes should now run
   indefinitely. Static tools help catch regressions: `-Xlint`, `jcstress`,
   or Clang's `-Wthread-safety` annotations flag out-of-order acquisition.

## Signals

- Do two thread dumps taken seconds apart show identical, parked stacks?
- Can you trace a closed cycle through the wait-for graph?
- Does every path that touches those locks now take them in one fixed order?

## Boundaries

This covers mutual-exclusion deadlocks between threads in one process.
Distributed deadlocks across services, database lock waits, and
connection-pool exhaustion wear the same mask but resolve with transaction
timeouts, lock ordering at the database, or pool sizing, not with a thread
dump.

Versions

The database has no other skills named deadlock-analysis.

Database snapshot: 13.11.2026 · package version 150b41ebfcb3 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100windbg-kernel-lock-deadlock-triage
    Use when kernel threads block on driver synchronization or Verifier reports a lock-order violation; build an owner/waiter graph. Not for treating every watchdog stop as a deadlock or listing every lock type with !locks.
  • 100deadlock-detection-harness
    Build deadlock-detection harnesses - extract lock-acquire-order graph via instrumentation, run cycle detection (DFS) to spot inconsistent ordering, use lock-acquire timeouts to surface rather than hang, JVM `jstack` / `gdb thread apply all bt` for postmortem analysis. Pair with…
  • 100deadlock-race-condition-troubleshooting
    Use this skill when detect and reproduce subtle multi-threaded race conditions and lock ordering deadlocks.
  • 100database-query-deadlock-lock-contention-debugging
    Use this skill when identify and resolve relational database transaction deadlocks and table lock contention.
  • 100mysql-1213
    排查 MySQL 报错「Deadlock found when trying to get lock; try restarting transaction」。当用户贴出包含这条报错的输出、或问这条报错怎么解决时使用。只读排查优先,不需要也不收集数据库密码。

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.