-
Notifications
You must be signed in to change notification settings - Fork 172
Dropping JoinHandle is problematic #79
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
Three was an attempt to make JoinHandle must-use, but it wasn’t successful.
Making docs more clear always helps!
These days, I’d probably suggest just always using thread::scope, which I
think stabilizes in the next release.
…On Thursday, 11 August 2022, Ian ***@***.***> wrote:
Hi @matklad <https://github.com/matklad> !
I've been using the pattern from your post on dropping Rust threads, and
recently got bitten by a bug along the lines of rust-lang/rust#48820
<rust-lang/rust#48820> , but I'm mainly opening
this issue to ask what you think might be a good approach to fixing this in
Rust.
Coming from a mostly C and C++ background, and with a few years of
mostly-hobby Rust experience, I find this situation feels very not-Rusty
and surprising. Part of the problem is that, IMO, it's not well documented
in either JoinHandle
<https://doc.rust-lang.org/std/thread/struct.JoinHandle.html> or Drop
<https://doc.rust-lang.org/std/ops/trait.Drop.html> documentation that
Rust does /not/ guarantee destructors will be called (the forget docs
<https://doc.rust-lang.org/core/mem/fn.forget.html> cover this nicely).
So, even a person who reads the post, and wonders about cleanup of the
worker thread, likely won't understand the problem if they look in the
obvious places.
As a first thought about a fix, I'd suggest doing each of:
- Improve the JoinHandle and Drop docs, around risk of destructors not
being called.
- Mark JoinHandle as #[must_use]
- Add a fn detach(self) method on JoinHandle
Do you think those would be reasonable fixes to propose, and if so how
would you suggest going about it? Thanks for your time, your blog (it's
been a great learning experience, and I still like that pattern when used
carefully ;) ), and especially rust-analyzer! I use rust-analyzer daily,
and recommend it whenever there's a good opportunity.
—
Reply to this email directly, view it on GitHub
<#79>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M5AG6O4W6Z56ZVCDE3VYSFMRANCNFSM56G3ZJ5Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @matklad !
I've been using the pattern from your post on dropping Rust threads, and recently got bitten by a bug along the lines of rust-lang/rust#48820 , but I'm mainly opening this issue to ask what you think might be a good approach to fixing this in Rust.
Coming from a mostly C and C++ background, and with a few years of mostly-hobby Rust experience, I find this situation feels very not-Rusty and surprising. Part of the problem is that, IMO, it's not well documented in either JoinHandle or Drop documentation that Rust does /not/ guarantee destructors will be called (the forget docs cover this nicely). So, even a person who reads the post, and wonders about cleanup of the worker thread, likely won't understand the problem if they look in the obvious places.
As a first thought about a fix, I'd suggest doing each of:
fn detach(self)
method on JoinHandleDo you think those would be reasonable fixes to propose, and if so how would you suggest going about it? Thanks for your time, your blog (it's been a great learning experience, and I still like that pattern when used carefully ;) ), and especially rust-analyzer! I use rust-analyzer daily, and recommend it whenever there's a good opportunity.
The text was updated successfully, but these errors were encountered: