【发布时间】:2021-08-31 14:19:40
【问题描述】:
golang 1.17 从堆栈更改为寄存器来处理参数
当我使用 atomic.SwapPointer 更改指针接收器的值时是否安全
下面是代码
//like this
func (this *A) Replace(a *A) {
//other business logic
//....
//business logic end
atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&this)), unsafe.Pointer(a))
}
【问题讨论】:
-
不安全就是不安全。你到底想做什么?
-
附带说明,建议不将您的方法接收者命名为
this或self。 -
不仅不安全,而且没用。它什么也没做。