In Golang, we can use:
type Data struct {
lock *sync.Mutex
}
or
type Data struct {
lock sync.Mutex
}
And, use like this:
func (d *Data) Update() {
d.lock.Lock()
defer d.lock.Unlock()
// update
}
The difference I can think of is that *sync.Mutex
needs instantiation to use only.
What is the difference between sync.Mutex
and *sync.Mutex
in Golang and which one is better?