gpt4 book ai didi

go - sync/mutex.go 中的 “_ = variable” 是什么意思

转载 作者:IT老高 更新时间:2023-10-28 13:11:07 24 4
gpt4 key购买 nike

同步/mutex.go:

func (m *Mutex) Unlock() {
if race.Enabled {
_ = m.state
race.Release(unsafe.Pointer(m))
}
...

_ = m.state是什么意思?

我知道 var _ interface = Object 的意思是检查 Object 是否实现了接口(interface)。

最佳答案

从提交日志来看,原因是“_ = m.state”确保m不为nil。

commit 5bb3a66a973ea87494b9197091e8c1f122080627
Author: Rémy Oudompheng <oudomphe@phare.normalesup.org>
Date: Mon Apr 8 23:46:54 2013 +0200

sync, sync/atomic: do not corrupt race detector after a nil dereference.

The race detector uses a global lock to analyze atomic
operations. A panic in the middle of the code leaves the
lock acquired.

Similarly, the sync package may leave the race detectro
inconsistent when methods are called on nil pointers.

R=golang-dev, r, minux.ma, dvyukov, rsc, adg
CC=golang-dev
https://golang.org/cl/7981043

关于go - sync/mutex.go 中的 “_ = variable” 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54304502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com