R8C Family General RTOS Concepts
The scheduler keeps record of the state of each task and selects from among them that are ready to execute and allocates the CPU to one of them. A scheduler helps to maximize CPU utilization among different tasks in a multi-tasking program and to minimize waiting time. There are generally two types of schedulers: non-preemptive and priority-based preemptive.
Non-preemptive scheduling or cooperative multitasking requires the tasks to cooperate with each other to explicitly give up control of the processor. When a task releases the control of the processor, the next most important task that is ready to run will be executed. A task that is newly assigned with a higher priority will only gain control of the processor when the current executing task voluntarily gives up the control. Figure 10 gives an example of a non-preemptive scheduling
Figure 10 Non-preemptive Scheduling
Priority-based preemptive scheduling requires control of the processor be given to the task of the highest priority at all time. In the event that makes a higher priority task ready to run, the current task is immediately suspended and the control of the processor is given to the higher priority task. Figure 11 shows an example of a preemptive scheduling.
The dispatcher gives control of the CPU to the task selected by the scheduler by performing context switching and changes the flow of execution. At any time an RTOS is running, the flow of execution passes through one of three areas: through the task program code, through an interrupt service routine, or through the kernel.
Page 9 of 18