pub trait Scheduler {
// Required methods
fn new_execution(&mut self) -> Option<Schedule>;
fn next_task(
&mut self,
runnable_tasks: &[&Task],
current_task: Option<TaskId>,
is_yielding: bool,
) -> Option<TaskId>;
fn next_u64(&mut self) -> u64;
}Expand description
A Scheduler is an oracle that decides the order in which to execute concurrent tasks and the
data to return to calls for random values.
The Scheduler lives across multiple executions of the test case, allowing it to retain some
state and strategically explore different schedules. At the start of each test execution, the
executor calls new_execution() to inform the scheduler that a new execution is starting. Then,
for each scheduling decision, the executor calls next_task to determine which task to run.
Required Methods§
Sourcefn new_execution(&mut self) -> Option<Schedule>
fn new_execution(&mut self) -> Option<Schedule>
Inform the Scheduler that a new execution is about to begin. If this function returns
None, the test will end rather than performing another execution. If it returns
Some(schedule), the returned Schedule can be used to initialize a ReplayScheduler for
deterministic replay.
Sourcefn next_task(
&mut self,
runnable_tasks: &[&Task],
current_task: Option<TaskId>,
is_yielding: bool,
) -> Option<TaskId>
fn next_task( &mut self, runnable_tasks: &[&Task], current_task: Option<TaskId>, is_yielding: bool, ) -> Option<TaskId>
Decide which task to run next, given a list of runnable tasks and the currently running
tasks. This method returns Some(task) where task is the runnable task to be executed
next; it may also return None, indicating that the execution engine should stop exploring
the current schedule.
is_yielding is a hint to the scheduler that current_task has asked to yield (e.g.,
during a spin loop) and should be deprioritized.
The list of runnable tasks is guaranteed to be non-empty. If current_task is None, the
execution has not yet begun.
Trait Implementations§
Source§impl Scheduler for Box<dyn Scheduler + Send>
impl Scheduler for Box<dyn Scheduler + Send>
Source§fn new_execution(&mut self) -> Option<Schedule>
fn new_execution(&mut self) -> Option<Schedule>
Scheduler that a new execution is about to begin. If this function returns
None, the test will end rather than performing another execution. If it returns
Some(schedule), the returned Schedule can be used to initialize a ReplayScheduler for
deterministic replay.Source§fn next_task(
&mut self,
runnable_tasks: &[&Task],
current_task: Option<TaskId>,
is_yielding: bool,
) -> Option<TaskId>
fn next_task( &mut self, runnable_tasks: &[&Task], current_task: Option<TaskId>, is_yielding: bool, ) -> Option<TaskId>
Some(task) where task is the runnable task to be executed
next; it may also return None, indicating that the execution engine should stop exploring
the current schedule. Read moreDyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".