Skip to content

Clarified docs in std::sync::RwLock#153555

Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:rwlock_docs
Open

Clarified docs in std::sync::RwLock#153555
asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215:rwlock_docs

Conversation

@asder8215
Copy link
Contributor

@asder8215 asder8215 commented Mar 8, 2026

This addresses the issue with the std::sync::RwLock docs in #115338. It centers around the following lines:

An RwLock will allow any number of readers to acquire the lock as long as a writer is not holding the lock.

It's true that the RwLock in theory should allow any number of readers to acquire the lock when a writer is not holding it, but this may not be true in the implementation and could be os dependent. I decided to replace "any number of readers" to "multiple", so that it implies that more than 1 reader can acquire the lock, but you can't necessarily take away that this value is unbounded.

@rustbot label +A-docs

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet

@rustbot rustbot added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Mar 8, 2026
@Mark-Simulacrum
Copy link
Member

Can we add a test that e.g. at least 2^32 read locks can be acquired and then document that? I've certainly written code (though not particularly cross-platform deployed code) that would benefit from a stronger guarantee here, and it seems like at least on tier 1 targets (for which we test in CI) we should be able to give a stronger guarantee than 'at least 2' :)

@asder8215
Copy link
Contributor Author

Can we add a test that e.g. at least 2^32 read locks can be acquired and then document that? I've certainly written code (though not particularly cross-platform deployed code) that would benefit from a stronger guarantee here, and it seems like at least on tier 1 targets (for which we test in CI) we should be able to give a stronger guarantee than 'at least 2' :)

I can do that for sure. Regarding the test, do you want me to add this in as a doctest within the RwLock::read() or within std/src/tests/sync/rwlock.rs? I think either way works.

@Mark-Simulacrum
Copy link
Member

I don't think it should be a doc test, seems too noisy for the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants