-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Deadlock with Rwlock and Thread with version 1.62 and 1.63 #101194
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
Comments
That's because your first (It's perhaps a bit surprising that |
I was expecting here that the first lock gets dropped as soon as we reach |
That's a very reasonable expectation, but unfortunately not what happens. Temporaries stay around until the end of the whole expression. It sometimes results in confusing situations with lock guards, just like in your snippet. It'd be nice if we can do something about this, but it's very tricky to change the language rules without breaking any existing code, or accidentally making the rules more confusing. Perhaps we just need a lint (in Clippy, or Rustc) that warns about confusing situations like this. |
The "test_gpio_process_events_multi_success" test currently hangs with an update to a newer version of Rust. The code here tries to read the value, locked, for each GPIO one by one. The values are updated in another thread with the help of write lock. More discussion around this issue can be found here. rust-lang/rust#101194 Breaking the while loop into three, one for each GPIO fixes it for now. This is the simplest solution possible right now. Signed-off-by: Viresh Kumar <[email protected]>
FWIW, the 'right' way to write that while loop would be something like this, by only locking once: while {
let d = data.read().unwrap();
d[0].is_some() || d[1].is_some()
} {
…
} |
From a common programmer's point of view, looks like something is broken somewhere since the compiler didn't complain at all. But I do understand what you are saying @m-ou-se . Thanks for quick response, really appreciate it. Lets see if someone can come up with a solution to this. |
Hmm, I wasn't aware that we can write while's statement this way, like body i.e.. Interesting. |
The "test_gpio_process_events_multi_success" test currently hangs with an update to a newer version of Rust. The code here tries to read the value, locked, for each GPIO one by one. The values are updated in another thread with the help of write lock. More discussion around this issue can be found here. rust-lang/rust#101194 Taking the lock only once fixes it for now. Signed-off-by: Viresh Kumar <[email protected]>
Closing this as not a bug. If you think the drop order of |
I tried this code:
I expected to see this happen: print [src/main.rs:25]
Instead, this happened: but it hangs
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: