# fatal error: all goroutines are asleep - deadlock! (RWMutex write lock)

- **ID:** `go/rwmutex-write-lock-deadlock`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A goroutine holding a read lock tries to acquire a write lock, causing a deadlock because write lock waits for all read locks to release.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Avoid holding read lock when acquiring write lock; release read lock first** (95% success)
   ```
   rw.RUnlock()
rw.Lock()
// write
rw.Unlock()
rw.RLock() // if needed again
   ```
2. **Use a single mutex instead of RWMutex if write locks are frequent** (90% success)
   ```
   var mu sync.Mutex
mu.Lock()
// write
mu.Unlock()
   ```

## Dead Ends

- **Using a separate mutex for writes** — Does not address the recursive locking issue; may still deadlock. (80% fail)
- **Increasing the number of goroutines** — More goroutines can exacerbate the deadlock. (90% fail)
