Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cond ¶
Cond behaves similarly to sync.Cond, but also supports context.Context. It has slight nuance in behaviour for Broadcast and Signal methods.
func (*Cond) Broadcast ¶
func (c *Cond) Broadcast()
Broadcast wakes all goroutines waiting on c.
Compared to sync.Cond.Broadcast, a lock _must_ be held when calling this.
func (*Cond) Signal ¶
func (c *Cond) Signal()
Signal wakes one goroutine waiting on c, if there is any.
Compared to sync.Cond.Signal, a lock _must_ be held when calling this.
func (*Cond) Wait ¶
func (c *Cond) Wait()
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 Broadcast or Signal.
Because c.L is not locked when Wait first resumes, the caller typically cannot assume that the condition is true when Wait returns. Instead, the caller should Wait in a loop:
c.L.Lock() for !condition() { c.Wait() } ... make use of condition ... c.L.Unlock()
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
A Mutex is a mutual exclusion lock. The zero value for a Mutex is an unlocked mutex.
func (*Mutex) Lock ¶
func (m *Mutex) Lock()
Lock locks m. If the lock is already in use, the calling goroutine blocks until the mutex is available.
func (*Mutex) LockWithContext ¶
LockWithContext locks m. It behaves similarly to calling m.Lock() but also adds support for context.Context deadlines.
The function returns ctx.Err() if the context deadlined, nil otherwise. The caller _must_ check the error code to decide if it should unlock the mutex later or not.