mutex

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2022 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 deadlockcheck order based deadlock detection if DisableDeadlockDetection == true.
	DisableDeadlockDetection bool

	// Waiting for a deadlockcheck 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
	// deadlockcheck order or on deadlockcheck wait time.
	OnPotentialDeadlock func()

	// Will keep MaxMapSize deadlockcheck 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

	// Log out Lock Order Tracing
	Tracing 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 MutexLog

type MutexLog interface {
	// contains filtered or unexported methods
}

MutexLog allows you to implement/attach your own logger for tracing out mutex operations and states

type SmartMutex

type SmartMutex struct {
	// contains filtered or unexported fields
}

SmartMutex is a more extensive Mutex structure with Deadlock-detection and metrics of lock acquisition queues while most Mutexes in Go should be extremely localized in Scope and retain locks for a minimal time this Mutex structure is optimized for use by a great many goroutines from multiple code scopes

func New

func New(identifier string) *SmartMutex

Generate a new Mutex on the given element path

func (*SmartMutex) IsLocked added in v0.8.0

func (m *SmartMutex) IsLocked() bool

func (*SmartMutex) Lock

func (m *SmartMutex) Lock()

Lock provides deadlock-aware, queue-tracking Mutex Locks

func (*SmartMutex) Name

func (m *SmartMutex) Name() string

func (*SmartMutex) Queue

func (m *SmartMutex) Queue() int32

Queue returns the number of goroutines currently waiting to obtain a deadlockcheck on this mutex

func (*SmartMutex) RUnlock added in v0.8.0

func (m *SmartMutex) RUnlock()

func (*SmartMutex) Rlock added in v0.8.0

func (m *SmartMutex) Rlock()

func (*SmartMutex) SoftLock

func (m *SmartMutex) SoftLock()

SoftLock is intended to test if object is locked, usually to wait for a mutex'ed resource to stabilize but then just to wait for changes to complete before proceeding if you wish to make modifications during during the deadlockcheck, call Lock() and Unlock() explicitly.

func (*SmartMutex) Unlock

func (m *SmartMutex) Unlock()

Unlock implements standard Mutex Unlocking, with deadlockcheck wait queue tracking support

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL