# panic: 运行时错误：无效的内存地址或空指针解引用（在 goroutine 中）

- **ID:** `go/nil-pointer-dereference-goroutine`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

某个 goroutine 尝试解引用空指针。通常发生在共享指针被另一个 goroutine 设置为 nil，或结构体字段在 goroutine 中使用前未初始化。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.Mutex
mu.Lock()
if ptr != nil {
    // use ptr
}
mu.Unlock()
   ```
2. **** (90% 成功率)
   ```
   go func(v MyStruct) {
    // use v
}(*ptr)
   ```

## 无效尝试

- **** — The pointer may become nil between the check and the dereference due to a race condition. Nil checks are not atomic with the dereference. (85% 失败率)
- **** — Recovering prevents the crash but leaves the program in an inconsistent state; the root cause remains. (90% 失败率)
