sync.Mutex
or sync.RWMutex
methods exposed GO-W401331// The zero value for a RWMutex is an unlocked mutex.
32//
33// RWMutex must not be copied after first use.
34type RWMutex struct {35 sync.RWMutex
36}
22// Mutex is a mutual exclusion lock. The zero value for a Mutex is an unlocked mutex.
23//
24// Mutex must not be copied after first use.
25type Mutex struct {26 sync.Mutex
27}
28
Exposing sync.Mutex
or sync.RWMutex
allows the caller to Lock
or Unlock
the underlying mutex, potentially leading to a deadlock.
package main
import (
"sync"
)
type Foo struct {
sync.Mutex
A int
}
package main
import (
"sync"
)
type Foo struct {
A int
lock sync.Mutex
}