在 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围棋,哪一个更好?