sync

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MPL-2.0 Imports: 16 Imported by: 512

Documentation

Overview

Package sync is an extension of the stdlib "sync" package. It has extra functionality that helps debug the use of synchronization primitives. The package should be importable in place of "sync". The extra functionality can be enabled by calling Enable() or passing a non-empty PPROF_SYNC environment variable to the process.

Several profiles are exposed on the default HTTP muxer (and to "/debug/pprof" when "net/http/pprof" is imported by the process). "lockHolders" lists the stack traces of goroutines that called Mutex.Lock that haven't subsequently been Unlocked. "lockBlockers" contains goroutines that are waiting to obtain locks. "/debug/lockTimes" or PrintLockTimes() shows the longest time a lock is held for each stack trace.

Disable any overhead and make env and functions no-ops by setting disable_pprof_sync tag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enable

func Enable()

func EnableContention

func EnableContention()

func EnableLockTimes

func EnableLockTimes()

func OnceFunc added in v0.5.1

func OnceFunc(f func()) func()

func OnceValue added in v0.6.0

func OnceValue[T any](f func() T) func() T

func PrintLockTimes

func PrintLockTimes(w io.Writer)

Writes out the longest time a Mutex remains locked for each stack trace that locks a Mutex.

Types

type Cond

type Cond = sync.Cond

type Locker

type Locker = sync.Locker

type Map

type Map = sync.Map

type Mutex

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

func (*Mutex) Lock

func (me *Mutex) Lock()

func (*Mutex) TryLock added in v0.6.0

func (me *Mutex) TryLock() bool

func (*Mutex) Unlock

func (me *Mutex) Unlock()

type Once

type Once = sync.Once

type Pool

type Pool = sync.Pool

type RWMutex

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

TODO: No lock times currently, was in the wrapped sync.Mutex before.

func (*RWMutex) Lock

func (me *RWMutex) Lock()

func (*RWMutex) RLock

func (me *RWMutex) RLock()

func (*RWMutex) RUnlock

func (me *RWMutex) RUnlock()

func (*RWMutex) TryLock added in v0.6.0

func (me *RWMutex) TryLock() bool

func (*RWMutex) TryRLock added in v0.6.0

func (me *RWMutex) TryRLock() bool

func (*RWMutex) Unlock

func (me *RWMutex) Unlock()

type WaitGroup

type WaitGroup = sync.WaitGroup

Jump to

Keyboard shortcuts

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