小编And*_*son的帖子

sync.Mutex 和 *sync.Mutex 哪个更好?

在 Go 中,我们可以使用:

type Data struct {
    lock  *sync.Mutex
}
Run Code Online (Sandbox Code Playgroud)

或者

type Data struct {
    lock  sync.Mutex
}
Run Code Online (Sandbox Code Playgroud)

并且,像这样使用:

func (d *Data) Update() {
   d.lock.Lock()
   defer d.lock.Unlock()
   // update
}
Run Code Online (Sandbox Code Playgroud)

我能想到的区别是只*sync.Mutex需要实例化即可使用。

是什么区别sync.Mutex*sync.Mutex围棋,哪一个更好?

mutex go

11
推荐指数
2
解决办法
5282
查看次数

标签 统计

go ×1

mutex ×1