pub trait Scheduler {
// Required methods
fn new_execution(&mut self) -> Option<Schedule>;
fn next_task(
&mut self,
runnable_tasks: &[TaskId],
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: &[TaskId],
current_task: Option<TaskId>,
is_yielding: bool
) -> Option<TaskId>
fn next_task( &mut self, runnable_tasks: &[TaskId], 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: &[TaskId],
current_task: Option<TaskId>,
is_yielding: bool
) -> Option<TaskId>
fn next_task( &mut self, runnable_tasks: &[TaskId], 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 more