-
Notifications
You must be signed in to change notification settings - Fork 113
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
Document/police/simplify locking hierarchy in Rust runtime #779
Comments
Suggestions:
Net, that would drop the number of distinct locks from 8 to 3:
|
One new discovery: there's also another lock hidden under the covers when doing output ( So: impl std::fmt::Debug for Channel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Channel {{ #msgs={}, #readers={}, #writers={}, label={:?} }}",
self.messages.read().unwrap().len(),
self.readers.load(SeqCst),
self.writers.load(SeqCst),
self.label,
)
}
} would be better as something like: impl std::fmt::Debug for Channel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Don't hold a lock while performing output.
let msg_count = { self.messages.read().unwrap().len() };
write!(
f,
"Channel {{ id={}, #msgs={}, #readers={}, #writers={}, label={:?} }}",
self.id,
msg_count,
self.reader_count.load(SeqCst),
self.writer_count.load(SeqCst),
self.label,
)
}
} |
Are the braces on the RHS necessary? I thought since it's just extracting an int, which is Copy, the scope of the lock is just until the end of line. |
I think you're right, but there seem to be some interesting gotchas with Rust temporary lifetimes that make me want to be extra careful. For example, from these docs I wonder if part of the original problem is triggered because the |
Current state is that we're down to 4 locks:
Each lock is taken alone in normal runtime operation, but there are a few places that use the combination So I think we can close this now. |
Also, our CI now (#915) runs both integration tests and a key unit test with TSAN, which should help prevent problems creeping in in future. |
There are various granular locks in the Rust runtime, and several places where multiple locks are acquired at the same time. The graph of locks-held is currently acyclic, but I'm concerned that it would be easy to accidentally change that and set ourselves up for a deadlock.
At the moment the graph seems to be:
There are also various places where the scope of locks could be significantly reduced, which should also help with this.
The text was updated successfully, but these errors were encountered: