# fatal error: sync: 解锁未加锁的 RWMutex

- **ID:** `go/mutex-unlock-of-unlocked-rwmutex`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

对 sync.RWMutex 调用 RUnlock() 的次数多于 RLock()，或在 Lock（写锁）之后错误地调用了 RUnlock。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0+ | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   mu.RLock()
defer mu.RUnlock()
// read section
   ```
2. **** (96% 成功率)
   ```
   func (c *Cache) Get(k string) (V, bool) {
    c.mu.RLock()
    defer c.mu.RUnlock()
    v, ok := c.m[k]
    return v, ok
}
   ```

## 无效尝试

- **** — Removes read concurrency and may not fix the mismatched lock/unlock pattern. (80% 失败率)
- **** — Hides the bug and can leave the lock in an inconsistent state. (90% 失败率)
