golang在32位系统下atomic.AddUint64导致程序崩溃及解决办法
某厂面试归来,发现自己落伍了!>>> package main import ( "sync/atomic" "unsafe" ) type a struct { x unsafe.Pointer y uint64 } func main() { p := new(a) atomic.AddUint64(&p.y, 1) } 在32位计算机上运行改程序,会出现错误: panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x4198bc] goroutine 1 [running]: runtime.panic(0x41c740, 0x445e4f) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist550409343/go/src/pkg/runtime/panic.c:266 +0xa6 sync/atomic.AddUint64(0x114434ac, 0x1, 0x0, 0x4107e3, 0x397fcc) C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist550409343/go/src/pkg/sync/atomic