Expand description
Key types and functions for multitasking that build on the basic Task
.
The main types of interest are:
TaskRef
: a shareable reference to aTask
that can actually be used, unlike the basicTask
type that cannot be spawned, modified, or scheduled in.JoinableTaskRef
: a derivative ofTaskRef
that allows the owner (a different task) to join that task, i.e., wait for it to exit, and to retrieve itsExitValue
.
The main standalone functions allow one to:
- Obtain the current task:
with_current_task()
is the preferred way, which accepts a closure that is invoked with access to the current task. This is preferred because it doesn’t need to clone the current task reference and is thus most efficient.get_my_current_task()
returns a cloned reference to the current task and is thus slightly more expensivewith_current_task()
.get_my_current_task_id()
is fastest if you just want the ID of the current task. Note that it is fairly expensive to obtain a task reference from a task ID.
- Register a kill handler for the current task –
set_kill_handler()
. - Yield the current CPU and schedule in another task –
schedule()
. - Switch from the current task to another specific “next” task –
task_switch()
.
To create new task, use the task builder functions in spawn
rather than attempting to manually instantiate a TaskRef
.
Re-exports
pub use scheduler::schedule;
Modules
Structs
- An error type indicating that the current task has not yet been initialized.
- A wrapper around
TaskRef
that allows this task to mark itself as exited. - Just like
core::panic::PanicInfo
, but with owned String types instead of &str references. - A struct holding data items needed to restart a
Task
. - An empty struct that invokes
schedule()
when it is dropped. - A structure that contains contextual information for a thread of execution.
- A shareable, cloneable reference to a
Task
that exposes more methods for task management and auto-derefs into an immutable&Task
reference. - A weak reference to a shared Task reference (
TaskRef
).
Enums
- The two ways a
Task
can exit, including possible return values and conditions. - The states used to initialize a new
Task
when creating it; seeTask::new()
. - An error type indicating that the current task was already initialized.
- The list of possible reasons that a given
Task
was killed prematurely. - The set of possible runstates that a
Task
can be in.
Functions
- Returns a list containing a snapshot of all tasks that currently exist.
- Bootstraps a new task from the current thread of execution.
- Returns a cloned reference to the current task.
- Returns the unique ID of the current task.
- Returns a
WeakTaskRef
(shared reference) to theTask
specified by the giventask_id
. - Registers a kill handler function for the current
Task
. - Takes ownership of the current
Task
’sKillHandler
function. - Switches from the current task to the given
next
task. - Invokes the given
function
with a reference to the current task. - Similar to
with_current_task()
, but also accepts a value that is passed to the givenfunction
or returned in the case of an error.
Type Aliases
- The signature of a Task’s failure cleanup function.
- The function signature of the callback that will be invoked when a
Task
panics or otherwise fails, e.g., a machine exception occurs.