Scheduler

Trait Scheduler 

Source
pub trait Scheduler {
    // Required methods
    fn next_to_run(&self) -> Option<Box<Thread>>;
    fn push_to_queue(&self, th: Box<Thread>);
    fn timer_tick(&self);
}
Expand description

A trait for a thread scheduler.

The Scheduler trait defines the common functionality expected from a thread scheduler. It provides an interface for managing threads, determining which thread to run next, and handling periodic timer interrupts. A thread scheduler is responsible for controlling the execution of threads in a system. The scheduler determines when each thread is allowed to run, how to handle context switching, and ensures fair allocation of CPU time among all threads.

This trait can be implemented by different types of schedulers, such as Round Robin, Priority-based, or Multi-level Queue schedulers. Each implementation may have a unique strategy for selecting the next thread to run and handling thread management.

Required Methods§

Source

fn next_to_run(&self) -> Option<Box<Thread>>

Peek a next thread to run.

This method checks the queue and returns the next thread to run. If no threads are available, it returns None.

§Returns

Returns an Option<Box<Thread>> containing the next thread to run or None if no threads are available to execute.

Source

fn push_to_queue(&self, th: Box<Thread>)

Push a thread th into scheduling queue.

This method adds the specified thread to the queue of threads waiting to be scheduled.

§Arguments
  • th - A boxed Thread object that represents the thread to be added to the scheduler’s queue.
Source

fn timer_tick(&self)

Called on every timer interrupt (1ms).

This method is triggered by the timer interrupt (e.g., every 1ms) and allows the scheduler to manage time slices, perform context switching, or adjust thread priorities as needed.

Implementations§

Source§

impl dyn Scheduler

Source

pub fn reschedule(&self)

Reschedule the current thread.

Source

pub(crate) unsafe fn park_thread( &self, th: &mut Thread, ) -> Result<ParkHandle, ()>

Park a thread ‘th’ and return ParkHandle.

Implementors§