liveBook · Manning

Deadlock detection

As explained in Learn Concurrent Programming with Go

Deadlock detection is the computational identification of a state in which executions are indefinitely waiting on one another or on unavailable resources.

Deadlock detection identifies executions that wait indefinitely for one another or unavailable resources, enabling alerts, process restarts, or retry logic after a deadlock occurs. section 11.2 section 11.2.1

A resource allocation graph represents executions and resources as nodes, with request and ownership edges. A cycle indicates a deadlock, and cycle detection can identify it. section 11.1.1 section 11.5

What Go detects—and misses

When every goroutine is blocked, Go’s runtime reports “fatal error: all goroutines are asleep - deadlock!” and includes stack details showing mutex and waitgroup waits. The runtime does not report the same deadlock when main sleeps while another goroutine waits on the waitgroup; the program prints “Done” and exits. section 11.2.1

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains graph cycles and Go runtime diagnostics, but limits runtime detection to states where all goroutines are blocked.
Examples
Demonstrates opposing mutex acquisition, Go fatal-error output, a sleeping main goroutine, and a rail-crossing resource cycle.
What it assumes
Assumes familiarity with goroutines, mutexes, waitgroups, and resource requests while illustrating their interactions through small examples.
What you can do after
Diagnose/debug with it: interpret Go’s deadlock stack trace and recognize why some blocked states evade runtime detection.
How it connects
Connects deadlocks with resource allocation graphs, cycle detection, goroutines, mutexes, waitgroups, and channels.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.