sync

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package sync implements synchronization primitives similar to those provided by the standard Go implementation. These are not safe to access from within interrupts, or from another thread. The primitives also lack any fairness guarantees, similar to channels and the scheduler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnceFunc added in v0.29.0

func OnceFunc(f func()) func()

OnceFunc returns a function that invokes f only once. The returned function may be called concurrently.

If f panics, the returned function will panic with the same value on every call.

func OnceValue added in v0.29.0

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

OnceValue returns a function that invokes f only once and returns the value returned by f. The returned function may be called concurrently.

If f panics, the returned function will panic with the same value on every call.

func OnceValues added in v0.29.0

func OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2)

OnceValues returns a function that invokes f only once and returns the values returned by f. The returned function may be called concurrently.

If f panics, the returned function will panic with the same value on every call.

Types

type Cond added in v0.14.0

type Cond struct {
	L Locker
	// contains filtered or unexported fields
}

func NewCond added in v0.19.0

func NewCond(l Locker) *Cond

func (*Cond) Broadcast added in v0.14.0

func (c *Cond) Broadcast()

func (*Cond) Signal added in v0.14.0

func (c *Cond) Signal()

func (*Cond) Wait added in v0.14.0

func (c *Cond) Wait()

type Locker added in v0.14.0

type Locker interface {
	Lock()
	Unlock()
}

type Map added in v0.13.0

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

func (*Map) Clear added in v0.34.0

func (m *Map) Clear()

func (*Map) Delete added in v0.13.0

func (m *Map) Delete(key interface{})

func (*Map) Load added in v0.13.0

func (m *Map) Load(key interface{}) (value interface{}, ok bool)

func (*Map) LoadAndDelete added in v0.26.0

func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool)

func (*Map) LoadOrStore added in v0.13.0

func (m *Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)

func (*Map) Range added in v0.14.0

func (m *Map) Range(f func(key, value interface{}) bool)

func (*Map) Store added in v0.13.0

func (m *Map) Store(key, value interface{})

func (*Map) Swap added in v0.39.0

func (m *Map) Swap(key, value any) (previous any, loaded bool)

Swap replaces the value for the given key, and returns the old value if any.

type Mutex

type Mutex = task.Mutex

type Once

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

func (*Once) Do

func (o *Once) Do(f func())

type Pool

type Pool struct {
	New func() interface{}
	// contains filtered or unexported fields
}

Pool is a very simple implementation of sync.Pool.

func (*Pool) Get

func (p *Pool) Get() interface{}

Get returns an item in the pool, or the value of calling Pool.New() if there are no items.

func (*Pool) Put

func (p *Pool) Put(x interface{})

Put adds a value back into the pool.

type RWMutex

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

func (*RWMutex) Lock

func (rw *RWMutex) Lock()

Lock locks rw for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available.

func (*RWMutex) RLock

func (rw *RWMutex) RLock()

RLock locks rw for reading.

It should not be used for recursive read locking; a blocked Lock call excludes new readers from acquiring the lock. See the documentation on the RWMutex type.

func (*RWMutex) RLocker added in v0.14.0

func (rw *RWMutex) RLocker() Locker

RLocker returns a Locker interface that implements the Lock and Unlock methods by calling rw.RLock and rw.RUnlock.

func (*RWMutex) RUnlock

func (rw *RWMutex) RUnlock()

RUnlock undoes a single RWMutex.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) TryLock added in v0.40.0

func (rw *RWMutex) TryLock() bool

TryLock tries to lock m and reports whether it succeeded.

Note that while correct uses of TryLock do exist, they are rare, and use of TryLock is often a sign of a deeper problem in a particular use of mutexes.

func (*RWMutex) TryRLock added in v0.40.0

func (rw *RWMutex) TryRLock() bool

TryRLock tries to lock rw for reading and reports whether it succeeded.

Note that while correct uses of TryRLock do exist, they are rare, and use of TryRLock is often a sign of a deeper problem in a particular use of mutexes.

func (*RWMutex) Unlock

func (rw *RWMutex) Unlock()

Unlock unlocks rw 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 RWMutex.RLock (RWMutex.Lock) a RWMutex and then arrange for another goroutine to RWMutex.RUnlock (RWMutex.Unlock) it.

type WaitGroup added in v0.14.0

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

func (*WaitGroup) Add added in v0.14.0

func (wg *WaitGroup) Add(delta int)

func (*WaitGroup) Done added in v0.14.0

func (wg *WaitGroup) Done()

func (*WaitGroup) Wait added in v0.14.0

func (wg *WaitGroup) Wait()

Jump to

Keyboard shortcuts

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