lock

package
v1.18.1-qos Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cond

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

Cond implements a condition variable. Typically sync.Cond should be preferred. However, this implementation supports cancellable waits.

func NewCond

func NewCond(l sync.Locker) *Cond

NewCond returns a new Cond with Locker l.

func (*Cond) Broadcast

func (c *Cond) Broadcast()

Broadcast wakes all goroutines waiting on c.

It is allowed but not required for the caller to hold c.L during the call.

func (*Cond) Signal

func (c *Cond) Signal()

Signal wakes one goroutine waiting on c, if there is any.

It is allowed but not required for the caller to hold c.L during the call.

Signal() does not affect goroutine scheduling priority; if other goroutines are attempting to lock c.L, they may be awoken before a "waiting" goroutine.

func (*Cond) Wait

func (c *Cond) Wait(ctx context.Context) error

Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Unlike in other systems, Wait cannot return unless awoken by Cond.Broadcast, Cond.Signal, or due to the context being cancelled.

Because c.L is not locked while Wait is waiting, the caller typically cannot assume that the condition is true when Wait returns, even if the returned value is nil. Instead, the caller should Wait in a loop:

c.L.Lock()
defer c.L.Unlock()

for !condition() {
	if err := c.Wait(ctx); err != nil {
		return err
	}
}
... make use of condition ...

type State added in v1.1.11

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

State represents a lockable state

func (*State) Acquire added in v1.1.11

func (s *State) Acquire()

Acquire acquires the write lock

func (*State) Lock added in v1.1.11

func (s *State) Lock() sync.Locker

Lock returns the underlying lock

func (*State) RAcquire added in v1.1.11

func (s *State) RAcquire()

RAcquire acquires the read lock

func (*State) RLock added in v1.1.11

func (s *State) RLock() sync.Locker

RLock returns the underlying read lock

func (*State) RRelease added in v1.1.11

func (s *State) RRelease()

RRelease releases the read lock

func (*State) Release added in v1.1.11

func (s *State) Release()

Release releases the write lock

Jump to

Keyboard shortcuts

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