From dee93c23f977feaf8241dcf25db2544b42049eb1 Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov Date: Sun, 14 Jul 2024 13:52:59 +0300 Subject: [PATCH] Improve RBMutex readme --- README.md | 13 +++++++++++++ rbmutex.go | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c79980b..6fe0497 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,19 @@ Hence, by the design `RBMutex` is a specialized mutex for scenarios, such as cac `RBMutex` extends `sync.RWMutex` internally and uses it as the "reader bias disabled" fallback, so the same semantics apply. The only noticeable difference is in the reader tokens returned from the `RLock`/`RUnlock` methods. +Apart from blocking methods, `RBMutex` also has methods for optimistic locking: +```go +mu := xsync.NewRBMutex() +if locked, t := mu.TryRLock(); locked { + // critical reader section... + mu.RUnlock(t) +} +if mu.TryLock() { + // critical writer section... + mu.Unlock() +} +``` + ## License Licensed under MIT. diff --git a/rbmutex.go b/rbmutex.go index 868b114..4cbd9c4 100644 --- a/rbmutex.go +++ b/rbmutex.go @@ -155,7 +155,6 @@ func (mu *RBMutex) TryLock() bool { return false } } - mu.inhibitUntil = time.Now() } return true }