Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashMutex ¶ added in v1.24.1
type HashMutex struct { KeyMutex // contains filtered or unexported fields }
HashMutex is a KeyMutex which reduces keys to a fixed number of bits so that there will only ever be a fixed number of mutexes. This means that there's no guarantee that two disctinct keys will use separate locks, but it is guaranteed that different calls with the same key, will use the same lock.
func NewHashMutex ¶ added in v1.24.1
NewHashMutex creates a new hash mutex with keys reduced to the given number of bits, e.g. if bits is 4, then keys be reduced to 16 possible values.
type KeyMutex ¶ added in v1.24.1
type KeyMutex struct {
// contains filtered or unexported fields
}
KeyMutex is a key based mutual exclusion lock. Different keys can hold the lock at the same time, same keys block.
m := KeyMutex{} unlock := m.Lock("key1") defer unlock()
Note that mutexes are not removed from the map when they are unlocked. Therefore the underlying map of mutexes can grow indefinitely.