Home |
RTKernel-32 Programming Manual Multitasking, Real-Time, and RTKernel-32 Task Switches Alternate APIs for RTKernel-32 |
Task SwitchesRTKernel-32 distinguishes three principle types of task switches: Blocking, Activating and Time Slice. A task always continues exactly where it has been previously suspended by a task switch. The three types of task switches occur under the following conditions: Blocking task switchA blocking task switch takes place whenever a task blocks itself, i.e., cannot continue to run. This will happen, for example, if a task attempts to retrieve data from an empty mailbox, or if a task releases the CPU for a certain time by calling function RTKDelay. RTKernel-32 will in this case select the highest priority task with state Ready to run. Should none of the application's tasks be ready, the Idle Task is activated. Activating task switchActivating task switches are performed whenever a task having a higher priority than the current task becomes Ready. An activating task switch is carried out, for example, if a task with a high priority is waiting for data at a mailbox when data is stored in the mailbox. The formerly blocked task can now continue to run and is activated. Time slice task switchTime slice task switches are performed by RTKernel-32's timer interrupt handler if the conditions given above are satisfied. Cooperative time slice task switches can also be triggered explicitly by a call to RTKDelay(0). In addition to the task switch types discussed above, cooperative and preemptive task switches are distinguished. Preemptive task switches are initiated by an interrupt handler; cooperative task switches are initiated by tasks. Blocking task switches are always cooperative, because they are not allowed to be initiated by interrupt handlers. A blocking preemptive task switch is considered an error by RTKernel-32. Activating task switches can occur in both forms using the same respective mechanisms. For example, a task or an interrupt handler storing data in a mailbox can lead to an activating task switch. In the first case, the task switch would be cooperative; in the latter, it would be preemptive. RTKernel-32 can be configured for cooperative or preemptive scheduling. When preemptions are disabled, task switches which would be preemptive with preemptions enabled are postponed by the kernel until the currently running task (or a task on a different CPU) calls a scheduler entrypoint (an RTKernel-32 API function). In this way, potentially preemptive task switches are converted to cooperative task switches if the application has not enabled preemptions. Multitasking, Real-Time, and RTKernel-32
|