diff --git a/deadlock.go b/deadlock.go index 36e76c3..6f8f81e 100644 --- a/deadlock.go +++ b/deadlock.go @@ -23,7 +23,7 @@ var Opts = struct { // 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 deetcted -- either based on + // 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. @@ -51,7 +51,7 @@ type Mutex struct { // If the lock is already in use, the calling goroutine // blocks until the mutex is available. // -// Unless deadlock detection is disabled, logs potential deadlocks to stderr, +// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, // calling Opts.OnPotentialDeadlock on each occasion. func (m *Mutex) Lock() { lock(m.mu.Lock, m) @@ -83,7 +83,7 @@ type RWMutex struct { // a blocked Lock call excludes new readers from acquiring // the lock. // -// Unless deadlock detection is disabled, logs potential deadlocks to stderr, +// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, // calling Opts.OnPotentialDeadlock on each occasion. func (m *RWMutex) Lock() { lock(m.mu.Lock, m) @@ -104,7 +104,7 @@ func (m *RWMutex) Unlock() { // RLock locks the mutex for reading. // -// Unless deadlock detection is disabled, logs potential deadlocks to stderr, +// Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, // calling Opts.OnPotentialDeadlock on each occasion. func (m *RWMutex) RLock() { lock(m.mu.RLock, m) @@ -185,12 +185,12 @@ func lock(lockFn func(), ptr interface{}) { lo.other(ptr) fmt.Fprintln(Opts.LogBuf, "All current goroutines:") Opts.LogBuf.Write(stacks) - lo.mu.Unlock() - Opts.mu.Unlock() fmt.Fprintln(Opts.LogBuf) if buf, ok := Opts.LogBuf.(*bufio.Writer); ok { buf.Flush() } + lo.mu.Unlock() + Opts.mu.Unlock() Opts.OnPotentialDeadlock() <-ch PostLock(4, ptr)