# 致命错误：同步：对未锁定的互斥锁解锁

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

## 根因

对未被同一协程锁定的互斥锁调用Unlock，通常由于缺少Lock或重复Unlock。

## 版本兼容性

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

## 解决方案

1. **Use defer to ensure Unlock is called exactly once after Lock** (99% 成功率)
   ```
   mu.Lock()
defer mu.Unlock()
// critical section
   ```
2. **Use sync.Mutex with proper pairing in all code paths** (90% 成功率)
   ```
   mu.Lock()
if condition {
    mu.Unlock()
    return
}
mu.Unlock()
   ```

## 无效尝试

- **Using recover() to catch panic** — Panic is fatal and cannot be recovered in Go runtime; program crashes. (100% 失败率)
- **Adding more Unlock calls to match Lock** — Double unlock causes panic; correct pairing is required. (90% 失败率)
