Debugging concurrent programs¶
Category: Testing and tools · Status: stub · Lessons: chapter 09, Testing and tools (planned)
One line: Thread dumps, deadlock detectors and tracing that show what every thread or task is waiting for at a given moment.
Also called: thread dump, deadlock detection, goroutine dump, stack dump.
How it connects¶
- See also: Deadlock
In each language¶
| Go | SIGQUIT (Ctrl-backslash) makes a program exit with a stack dump ↗; runtime/pprof ↗ has goroutine, block and mutex profiles |
| Java | jcmd Thread.print ↗ prints all threads with stack traces; ThreadMXBean.findDeadlockedThreads ↗ finds cycles of deadlocked threads |
| Python | faulthandler.dump_traceback ↗ dumps the tracebacks of all threads, also after a timeout or on a signal |
| C# | dotnet-stack ↗ inspects managed stack traces |
| Elsewhere | GDB ↗ thread apply all bt applies bt to every thread, printing a backtrace for each |
Where to read more¶
- In a sibling library: Rust: Instrumenting async code ↗
- In a sibling library: Go: All goroutines are asleep ↗
- In the books: Effective Concurrency in Go, Burak Serdar — ch. 10, 'Troubleshooting Concurrency Issues'
- In the books: Programming with POSIX Threads, David R. Butenhof — ch. 8, 'Hints to Avoid Debugging'
- In the books: C++ Concurrency in Action, Anthony Williams — ch. 11, 'Testing and debugging multithreaded applications'
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 11, 'Concurrency Hazards'
- In the books: Mastering C++ Multithreading, Maya Posch — ch. 6, 'Debugging Multithreaded Code'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 9, 'Concurrency in Practice' → 'Debugging concurrent programs'
- Notes: tools for concurrent programming ↗