Skip to content

Commit

Permalink
Improve RBMutex readme
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Jul 14, 2024
1 parent f53fbc1 commit dee93c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion rbmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func (mu *RBMutex) TryLock() bool {
return false
}
}
mu.inhibitUntil = time.Now()
}
return true
}
Expand Down

0 comments on commit dee93c2

Please sign in to comment.