# 恐慌：同步：解锁未锁定的互斥锁

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

## 根因

在互斥锁未锁定的情况下调用Unlock()，通常由于逻辑错误或重复解锁导致。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Always lock before unlocking. Use defer mutex.Unlock() immediately after locking to ensure proper pairing.
   ```
2. **** (90% 成功率)
   ```
   Use sync.RWMutex and ensure Lock/Unlock are in the same goroutine scope to avoid mismatched calls.
   ```

## 无效尝试

- **** — The panic will crash the program; ignoring it is not possible. (100% 失败率)
- **** — Manual tracking is error-prone and can still race; it does not solve the root cause. (80% 失败率)
- **** — If the lock is not acquired, defer will still call Unlock and cause the same panic. (60% 失败率)
