# fatal error: sync: 解锁未加锁的互斥锁

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

## 根因

对当前未被本 goroutine 锁定的互斥锁调用了 Unlock()，原因是重复解锁、未加锁就解锁，或复制了互斥锁值。

## 版本兼容性

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

## 解决方案

1. **** (96% 成功率)
   ```
   mu.Lock()
defer mu.Unlock()
// critical section
   ```
2. **** (94% 成功率)
   ```
   type Counter struct {
    mu sync.Mutex
    n  int
}
func inc(c *Counter) { c.mu.Lock(); defer c.mu.Unlock(); c.n++ }
   ```

## 无效尝试

- **** — This is a fatal runtime error, not a recoverable panic; the process aborts regardless. (98% 失败率)
- **** — This breaks the critical section semantics and can deadlock if the same goroutine already holds the lock. (85% 失败率)
