go
runtime_error
ai_generated
true
panic: runtime error: invalid memory address or nil pointer dereference (atomic load)
ID: go/atomic-operation-misuse
80%Fix Rate
85%Confidence
0Evidence
2024-10-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.4 | active | — | — | — |
| 1.23 | active | — | — | — |
Root Cause
Using atomic operations on a nil pointer or unaligned memory, causing a panic.
generic中文
对空指针或未对齐的内存使用原子操作,导致恐慌。
Workarounds
-
95% success Ensure pointer is initialized before atomic operations
var val int64 atomic.StoreInt64(&val, 42)
-
90% success Use atomic.Value for arbitrary types
var v atomic.Value v.Store(42) val := v.Load().(int)
Dead Ends
Common approaches that don't work:
-
Using mutex instead of atomic but not initializing pointer
60% fail
Mutex also requires valid pointer; same issue.
-
Ignoring alignment requirements for atomic operations on struct fields
70% fail
Atomic operations require natural alignment; panic may occur on some architectures.