-
Notifications
You must be signed in to change notification settings - Fork 13.3k
proposal for new task API #10614
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
I can imagine that joining by default will cause a lot of confusion when code that just calls |
I agree that both APIs needs to exist, I'm not sure I'm comfortable with the default being to return a handle. We already do support both methods today, but the "spawn with handle" is a little more painful than it might need to be. |
cc #8160. |
I thought it would be possible to simply detach in the destructor, but that removes the possibility of returning a value to be joined because it will leak. |
I also think that having the default spawn join when a returned handle goes out of scope is surprising, and I'd prefer to use standard synchronization primitives for joining rather than a custom type if possible. If we were to introduce a type called |
We discussed this at the triage meeting today, and came to the following conclusions:
For these reasons, we have decided to close this. We are still open to hearing reasons why we should move towards an API such as this, but we would want our concerns above to be addressed to see why this flavor of an API would be a better choice. |
Clear with drain Fixes rust-lang#10572: both the original intent of the issue (extending `clear_with_drain`) and the false negative for `collection_is_never_read` I found in the process are fixed by this PR. changelog: [`clear_with_drain`]: extend to 5 other types of containers. [`collection_is_never_read`]: fix false negative for `String`s.
The
Task
struct will have a destructor calling join, so there will always be a synchronization point withspawn
. If the task fails, thejoin
call will propagate the failure. Atry_join
method can be added to handle an error.A more complex example:
https://github.com/thestinger/rust-core/blob/master/test/thread.rs#L41-L78
Note that since it's using detached threads, it will happily leak the
proc
and the queue in cases of pathological scheduling. Of course, that's just a case of exiting early without doing more work than required.The text was updated successfully, but these errors were encountered: