-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
maitake: task cancellation #264
Comments
It might be interesting to be able to handle this at the leaf future level as well, to simulate task cancellations on violation of something. For example, my idea would basically be to allow the allocator to "kill" a task if it asks for something like 240TiB of memory. |
@jamesmunns yeah, i think a |
This branch implements cancellation for spawned tasks. A task can be cancelled through its `JoinHandle` (`JoinHandle::cancel`), or through a `TaskRef` to it (`TaskRef::cancel`). When a task is cancelled, a bit is set on its state field indicating that it has been canceled, and the task is woken. A leaf future inside a task can cancel that task by calling `Scheduler::current_task()` to get a `Taskref` to itself, and then canceling that `TaskRef`. When the scheduler polls a task with the canceled bit set, it doesn't poll the future, but instead notifies the task's `JoinHandle` and drops its own reference to that task. Once the `JoinHandle` and all `TaskRef`s that own reference counts for that task are dropped, the task can be deallocated. A task may be canceled in a state where the `Future` has completed but the `JoinHandle` hasn't consumed the `Output` from the `Future` yet. In that case, the `JoinHandle` still returns an error, but the error indicates that the task was canceled after completion, and allows recovering the future's `Output`. anyway. Closes #264
PR #261 adds a
JoinHandle
type formaitake
's tasks. This allows awaiting the completion of a task. In most other async runtimes,JoinHandle
types also provide a way to remotely cancel/abort a task. We should implement that.This would work by setting a status bit indicating the task is cancelled. The code for polling a task would then check this bit when transitioning to the polling state. If the bit is set, the task transitions to terminated, and drops the inner future.
The text was updated successfully, but these errors were encountered: