Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Opts = struct { // Mutex/RWMutex would work exactly as their sync counterparts // -- almost no runtime penalty, no deadlock detection if Disable == true. Disable bool // Would disable lock order based deadlock detection if DisableLockOrderDetection == true. DisableLockOrderDetection bool // Waiting for a lock for longer than DeadlockTimeout is considered a deadlock. // Ignored is DeadlockTimeout <= 0. DeadlockTimeout time.Duration // OnPotentialDeadlock is called each time a potential deadlock is detected -- either based on // lock order or on lock wait time. OnPotentialDeadlock func() // Will keep MaxMapSize lock pairs (happens before // happens after) in the map. // The map resets once the threshold is reached. MaxMapSize int // Will dump stacktraces of all goroutines when inconsistent locking is detected. PrintAllCurrentGoroutines bool mu *sync.Mutex // Protects the LogBuf. // Will print deadlock info to log buffer. LogBuf io.Writer }{ DeadlockTimeout: time.Second * 30, OnPotentialDeadlock: func() { os.Exit(2) }, MaxMapSize: 1024 * 64, LogBuf: os.Stderr, // contains filtered or unexported fields }
Opts control how deadlock detection behaves. Options are supposed to be set once at a startup (say, when parsing flags).
Functions ¶
This section is empty.
Types ¶
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
A Mutex is a drop-in replacement for sync.Mutex. Performs deadlock detection unless disabled in Opts.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
An RWMutex is a drop-in replacement for sync.RWMutex. Performs deadlock detection unless disabled in Opts.
func (*RWMutex) Lock ¶
func (m *RWMutex) Lock()
Lock locks rw for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available. To ensure that the lock eventually becomes available, a blocked Lock call excludes new readers from acquiring the lock.
Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*RWMutex) RLock ¶
func (m *RWMutex) RLock()
RLock locks the mutex for reading.
Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*RWMutex) RLocker ¶
RLocker returns a Locker interface that implements the Lock and Unlock methods by calling RLock and RUnlock.
func (*RWMutex) RUnlock ¶
func (m *RWMutex) RUnlock()
RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It is a run-time error if rw is not locked for reading on entry to RUnlock.
func (*RWMutex) Unlock ¶
func (m *RWMutex) Unlock()
Unlock unlocks the mutex for writing. It is a run-time error if rw is not locked for writing on entry to Unlock.
As with Mutexes, a locked RWMutex is not associated with a particular goroutine. One goroutine may RLock (Lock) an RWMutex and then arrange for another goroutine to RUnlock (Unlock) it.