-
Notifications
You must be signed in to change notification settings - Fork 48
Implement scoped tasks #40
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
Conversation
I have simply thought about the soundness of "scoped-task", there are four kinds of condition just similar as "scoped-threads":
|
If we keep a handle to the task stored in the The real issue is the fact that the outer
The only real option would be to have some kind of guard inside of the I'd love to be proven wrong here, but I think that the only way to have a sound implementation of scoped tasks would be to have it be a pub fn block_on_scoped<'env>(f: impl FnOnce(&Scope<'env>) -> impl Future) {
...
}
let mut i = 1;
block_on_scoped(|scope| {
let i = &mut i;
let (runnable, task) = scope.spawn(async move { *i += 1; });
async move {
...
}
}); However, that would involve quite a few caveats. For instance, for large programs, you would have to pass the All in all, it's probably a job best suited for a crate outside of this one, and would require a careful hand to ensure that everything is sound. |
Yes I think your are right, considering the As you said, maybe it is not the best way to embed this feature into |
This PR implements "scoped tasks", similar to scoped threads in
libstd
andcrossbeam
. It provides a safe abstraction for borrowing variables from the local stack in tasks. The goal is to enable scoped tasks inblocking
.For the time being, this relies on
async-channel
, which useslibstd
for the time being. However, once we move it tono_std
, this should not be an issue.This PR probably needs a review for soundness. MIRI doesn't raise any red flags
but it's 100% possible that I missed something.Just saw something I missed, let me take care of that.