# 恐慌：sync: 解锁未锁定的互斥锁

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

## 根因

对当前未锁定的互斥锁调用 sync.Mutex.Unlock()，通常是由于重复 Unlock 或缺少 Lock。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use defer mu.Unlock() immediately after Lock() to ensure pairing:
mu.Lock()
defer mu.Unlock()
   ```
2. **** (85% 成功率)
   ```
   Review all Lock/Unlock pairs and ensure they are balanced. Consider using sync.RWMutex if read-heavy.
   ```

## 无效尝试

- **** — Hides the bug but does not fix the incorrect locking logic; may cause deadlocks later. (80% 失败率)
- **** — Channels have different semantics and may not fit the use case; also more complex. (60% 失败率)
