Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex is an enhanced version of the standard sync.RWMutex. It has the all methods sync.RWMutex with exact same semantics. It gives more methods to give upgradable-read feature.
The new semantics for upgradable-read are as follows: Multiple goroutines can get read-lock together with a single upgradable-read-lock. Only one goroutine can have a write-lock and no read-lock/upgradable-read-lock can be acquired in this state. There can be only a single goroutine keeping the upgrade-read-lock. RWMutex is not reentrant.
Usage of the RWMutex:
mutex.UpgradableRLock() defer mutex.UpgradableRUnlock() // read-lock acquired section. We can return here safely if an error occurs mutex.UpgradeWLock() // critical section with exclusive right access
func (*RWMutex) UpgradableRLock ¶
func (rw *RWMutex) UpgradableRLock()
UpgradableRLock acquires an upgradable-read-lock which can be later upgraded to write-lock, Example usage:
mutex.UpgradableRLock() defer mutex.UpgradableRUnlock() // read-lock acquired section. We can return here safely if an error occurs mutex.UpgradeWLock() // critical section with exclusive right access
func (*RWMutex) UpgradableRUnlock ¶
func (rw *RWMutex) UpgradableRUnlock()
UpgradableRUnlock unlocks either the write-lock if it is upgraded or unlock just the upgradeableRead-lock if not upgraded
func (*RWMutex) UpgradeWLock ¶
func (rw *RWMutex) UpgradeWLock()
UpgradeWLock upgrade the read lock to the write lock