Skip to content
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

Lock is not immediately released after acquiring value in function argument #5056

Closed
pinkiebell opened this issue Sep 27, 2022 · 3 comments
Closed
Labels
A-tokio Area: The main tokio crate C-question User questions that are neither feature requests nor bug reports M-sync Module: tokio/sync

Comments

@pinkiebell
Copy link

Version
v1.21.1

Platform
Linux 5.18.19 #1 SMP
aarch64 GNU/Linux

Description

Link to reproduce

There is a deadlock in the above example that only happens if we acquire a lock as part of a function call/arguments.
The body of the function will in turn acquire a lock again and deadlocks in the above example.

As a user I expect that the lock will be released after the value was loaded, like in local let bindings. But this is not the case here.

@pinkiebell pinkiebell added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Sep 27, 2022
@sfackler
Copy link
Contributor

sfackler commented Sep 27, 2022

This is how the Rust language works - temporary values are destroyed upon the completion of the statement that created them, so in this case the guard returned by the lock call will remain alive until the call to func completes.

@pinkiebell
Copy link
Author

Thanks for the fast answer. I wasn't sure about how rust determines how that should work.
Is that documented somewhere?

Btw, Feel free to close this issue 👍

@sfackler
Copy link
Contributor

https://doc.rust-lang.org/reference/expressions.html#temporaries

@Darksonn Darksonn added C-question User questions that are neither feature requests nor bug reports M-sync Module: tokio/sync and removed C-bug Category: This is a bug. labels Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-question User questions that are neither feature requests nor bug reports M-sync Module: tokio/sync
Projects
None yet
Development

No branches or pull requests

3 participants