# fatal error: all goroutines are asleep - deadlock! (mutex)

- **ID:** `go/goroutine-mutex-deadlock`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Two or more goroutines hold locks and wait for each other to release them, causing a circular wait condition.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |
| 1.20 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Always lock mutexes in the same order** (95% success)
   ```
   // Lock mu1 then mu2 consistently
mu1.Lock()
mu2.Lock()
// unlock in reverse order
   ```
2. **Use trylock with a fallback** (80% success)
   ```
   if mu.TryLock() {
    defer mu.Unlock()
    // critical section
} else {
    // handle contention
}
   ```

## Dead Ends

- **Use a single global mutex** — A single mutex can cause contention but not deadlock if used correctly; however, if nested locks are needed, it can still deadlock. (50% fail)
- **Ignore the deadlock and restart the program** — Temporary fix; the deadlock will recur. (90% fail)
