# 致命错误：sync：解锁未锁定的互斥锁

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

## 根因

尝试解锁一个未锁定的互斥锁，通常是由于重复解锁或在错误的 goroutine 中解锁。

## 版本兼容性

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

## 解决方案

1. **Always use defer to unlock immediately after lock** (95% 成功率)
   ```
   mu.Lock()
defer mu.Unlock()
// critical section
   ```
2. **Ensure unlock is called exactly once per lock** (90% 成功率)
   ```
   Use paired Lock/Unlock in same function; avoid manual unlock in error paths without defer.
   ```

## 无效尝试

- **Adding a flag to check if mutex is locked** — Mutex does not expose lock state; race conditions on the flag. (85% 失败率)
- **Using recover() to ignore the panic** — Recovering does not fix the logic error; may cause data corruption. (70% 失败率)
