Documentation
¶
Overview ¶
Package sync provides synchronization utilities.
Package sync provides sync utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnlockOfUnlockedMutex reports an attempt to unlock an unlocked mutex. ErrUnlockOfUnlockedMutex = errors.New("unlock of unlocked reentrant mutex") // ErrUnlockFromAnotherGoroutine reports an attempt to unlock a mutex owned by another goroutine. ErrUnlockFromAnotherGoroutine = errors.New("unlock from non-owner goroutine") // ErrUnlockWithNegativeCount Unlock with negative count. ErrUnlockWithNegativeCount = errors.New("unlock with negative count") )
Functions ¶
This section is empty.
Types ¶
type ReentrantMutex ¶
type ReentrantMutex struct {
// contains filtered or unexported fields
}
A ReentrantMutex is a reentrant mutual exclusion lock. The zero value for a ReentrantMutex is an unlocked mutex.
A ReentrantMutex must not be copied after first use.
In the terminology of the Go memory model, the n'th call to ReentrantMutex.Unlock by the owning goroutine "synchronizes before" the m'th call to ReentrantMutex.Lock for any n < m, accounting for recursion levels. ReentrantMutex allows the same goroutine to acquire the lock multiple times without deadlock. It tracks the owning goroutine and recursion level; only the owning goroutine may unlock it, and the mutex is released when the recursion level reaches zero.
ReentrantMutex implements the sync.Locker interface.
func NewReentrantMutex ¶
func NewReentrantMutex() *ReentrantMutex
NewReentrantMutex creates and initializes a new ReentrantMutex.
func (*ReentrantMutex) Lock ¶
func (rm *ReentrantMutex) Lock()
Lock locks rm. If the lock is already held by the current goroutine, the recursion count is incremented. Otherwise, the calling goroutine blocks until the rmutex is available.
func (*ReentrantMutex) Unlock ¶
func (rm *ReentrantMutex) Unlock()
Unlock unlocks rm. It panics if rm is not locked on entry to Unlock.
Unlock must be called by the goroutine that owns the lock. If the recursion count is greater than 1, it is decremented. If the recursion count reaches 0, the lock is released.
A locked ReentrantMutex is associated with a particular goroutine. It is not allowed for one goroutine to lock a ReentrantMutex and then arrange for another goroutine to unlock it.