# panic：sync：解锁未加读锁的 RWMutex

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

## 根因

在没有对应 RLock() 的情况下调用 RUnlock()，或该锁实际是写锁。RWMutex 上锁/解锁配对不匹配会 panic。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **** (94% 成功率)
   ```
   mu.RLock()
defer mu.RUnlock()
// read-only access
   ```
2. **** (90% 成功率)
   ```
   func (s *Store) Get(k string) (V, bool) {
    s.mu.RLock()
    defer s.mu.RUnlock()
    v, ok := s.m[k]
    return v, ok
}
   ```

## 无效尝试

- **** — Loses read concurrency benefits and may not fix the underlying mismatched lock/unlock logic. (70% 失败率)
- **** — Hides the bug; the RWMutex internal state may be inconsistent, leading to deadlocks later. (88% 失败率)
