-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Clarified docs in std::sync::RwLock + added test to ensure that max reader count is respected #153555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
asder8215
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
asder8215:rwlock_docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−2
Open
Clarified docs in std::sync::RwLock + added test to ensure that max reader count is respected #153555
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this arithmetic overflow look like? A panic?
I think we want to know if there are new targets added that don't meet the target (MAX_READERS here). I'd rather see the cfg on the MAX_READERS constant and we can lower it / set it to different values depending on the cfg.
E.g.:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no explicit panic in the arithmetic overflow for the no_threads
RwLockimpl. If we take a look at the code inside library/std/src/sys/sync/rwlock/no_thread.rs:There is overflow that could occur on
modewhen we reachisize::MAXreaders and decide to do anotherRwLock::read()call here (though this could end up being silent).I have a different PR as well addressing what I find odd about the
RwLock::writehere with always replacing themodevalue with -1 even when it's reader locked.Should there be an assertion here that does something similar to
rwlock/futex.rswith erroring with the message "too many active read locks on RwLock" when we go beyond the max reader count? I'm not sure how to test this locally or if CI would be able to run the max reader test we have here on the no_threads impl to see if it works as intended in.I can do this. I'm a bit concerned about the
rwlock/queue.rsimplementation because technically the max readers isusize::MAX - (1 << 4)from my understanding of this piece of code:However, at least from my understanding of
RwLock::lock_contended():If we receive
Nonefromread_lock()or reach that possible max reader count, the pending reader will try to acquire the lock again another time.I guess my questions for this scenario are:
MAX_READERtousize::MAX - (1 << 4)for targets associated withrwlock/queue.rs? (this will make the test run slower on 64 bit machines though, wouldn't it?)MAX_READERtousize::MAX - (1 << 4), would it be possible for this to stack overflow as all allocation for thisRwLockimpl is stack allocated?The last question I have is I'm aware that for solid_asp3 it
RwLock::read()depends on howrwl_loc_rdlis internally implemented. That's my understanding at least from looking atstd/src/sys/pal/solid/abi/mod.rs:I've been trying to find information about what solid_asp3
rwl_loc_rdldoes, but I struggled to find sources of its implementation. Do you know where I could go to to find solid_asp3's internal implementation ofrwl_loc_rdl(or do you happen to know the max reader count for solid_asp3)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't copy/paste method bodies, just link to them if you want to reference something specific. Much easier to follow the conversation if there's not large walls of code.
Yes, I think it would be good to use checked_ arithmetic operations and panic if we overflow the counter, rather than depending on whether overflow-checks are enabled for soundness.
I don't think we can afford to run up to ~2^64 iterations, that's going to be too slow. Asserting a smaller limit on those targets (e.g., 2^32 or so) should be fine though. In
cfg!(miri)I'd recommend asserting we can acquire (say) 100 reader locks to keep the test fast enough.I don't think so? The stack allocation for the reader locks is only if we're parked (i.e., waiting for some other thread), right?
Per https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html, @kawadakk is the target maintainer. Can you confirm what we should expect from the RwLock implementation on that target?
Let's assume 2^30 for now if we don't hear otherwise.