Repository navigation
feat(rwlock): add an upgradable readers-writer lock - #366
Open
Kaileshwar16 wants to merge 2 commits into
Open
Kaileshwar16 wants to merge 2 commits into
Kaileshwar16 wants to merge 2 commits into
Conversation
orthur2
self-requested a review
October 23, 2026 15:39
orthur2
reviewed
Oct 24, 2026
orthur2
left a comment
Contributor
There was a problem hiding this comment.
Thanks for taking this on. The reservation protocol and the cancellation paths look sound to me.
On the borrowed guards question, I think they’re fine for a first version. The existing owned guards hold an Arc<RwLock>, which we can’t get by projecting an Arc<UpgradableRwLock>, so owned support couldn’t reuse them as they are.
Please also add UpgradableRwLock to the API map in lib.rs and README.
Kaileshwar16
force-pushed
the
feat/169-upgradable-rwlock
branch
from
October 24, 2026 09:53
e675886 to
4c117c6
Compare
orthur2
approved these changes
Oct 25, 2026
orthur2
left a comment
Contributor
There was a problem hiding this comment.
Thanks, looks good to me now.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #169.
Add
UpgradableRwLockwith ordinary readers, exclusive writers, and one upgradablereader. Support asynchronous upgrade, guard-preserving
try_upgrade(), and downgrade toan ordinary reader.
Cancelling a pending upgrade releases the consumed guard and its permits. Include rustdoc
examples and deterministic tests for ordering, cancellation, reader limits, cross-thread
visibility, and guard traits.
Design Notes
Reuse the existing RwLock and semaphore implementation. Writers and upgradable readers
acquire a FIFO reservation before requesting data permits, preventing an upgrade from
queuing behind a writer waiting for the upgrader’s read permit.
Ordering is FIFO within each queue, rather than globally: ordinary readers can pass
writers waiting for the reservation. Existing RwLock behavior remains unchanged.
Validation:
cargo x lintandcargo x checkpassed.cargo x test: 625 passed.cargo x miri: 194 passed, 10 existing skips.This is an initial implementation intended to help settle the API design in #169. I'd especially appreciate feedback on the two-queue fairness model, cancellation semantics for a pending upgrade, and whether borrowed guards are sufficient for the first version. I'm happy to adjust the design based on maintainer feedback.