-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Ambiguity in RwLock documentation about multiple .read() calls on the same thread #149693
Copy link
Copy link
Open
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Location (URL)
https://doc.rust-lang.org/std/sync/struct.RwLock.html#method.read
Summary
We're exploring backing RwLock with primitives from https://abseil.io/docs/cpp/guides/synchronization and encountered a surprise: RwLock is not documentedly reentrant for read lock holders, but there's an example that would fail if it wasn't. On the other hand, the documented "Potential deadlock example" is related. Then in the docs for
fn readwe see "This function might panic when called if the lock is already held by the current thread."I think this means that it's not safe to call
.read()on an RwLock multiple times in the same thread - but then there's this test in crossbeam-utils that fails on line 16 when the abseil deadlock detector is active, which is correct if the RwLock isn't reentrant.Should we revise the documentation to clarify that RwLock isn't reentrant, since that's what's already implied? Or do we need to treat the example from crossbeam-utils as evidence that RwLock needs to be permissive in this regard even though it's a potential bug-in-waiting based on the deadlock example?
In favor of revising to clarify you shouldn't call
.read()more than once per thread:In favor of clarifying to allow
.read()more than once per thread:I'd be happy to send a doc update that makes the example use multiple threads rather than calling
.read()(or add a comment describing how they should be in threads) and adds some warning text to.read()about only holding one reader lock per thread, but I wanted to clarify what direction we should go before doing so.So: what's the consensus?