Skip to content

Post: Joining threads immediately as they finish in Rust #6645

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

Merged

Conversation

jpmelos
Copy link
Contributor

@jpmelos jpmelos commented May 16, 2025

This is a post about joining multiple threads in Rust in a way that they can be joined immediately as they finish.

Copy link
Contributor

@mariannegoldin mariannegoldin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Approved with a syntax correction.

@mariannegoldin mariannegoldin merged commit 4f697fc into rust-lang:master May 16, 2025
1 check passed
@ericseppanen
Copy link
Contributor

Thanks for the submission!

I was reviewing this post with one of the rust standard library authors, and we both felt that this article could use some improvement, so that it doesn't cause confusion among readers new to Rust. Specifically, it should mention the fact that thread::spawn can be used in "detached" mode (by just dropping the JoinHandle), where the caller does not need to call join() at all.

If we've misunderstood, feel free to continue the conversation. I'm going to revert the PR in this week's issue because we're already late and need to get it published soon, but feel free to resubmit again next week! Apologies for the mixed messages; it was a miscommunication on our end.

If a timely result is needed from the spawned thread, it's fairly common to pass a Sender to into the spawned function and have it transmit information that way, instead of using the return value and doing more work to loop over the JoinHandles repeatedly. It might also help to mention this approach.

@jpmelos
Copy link
Contributor Author

jpmelos commented May 16, 2025

Thanks, I'll edit the post and try again.

@jpmelos jpmelos deleted the joining-multiple-threads-rust branch May 16, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants