TASKS
TASKS
• A TASK
A task is an independent thread of execution that competes with other tasks for processor time.
Applications are broken down into simple finite state machines for task execution. In most preemptive-
scheduling RTOS kernels, tasks generally have three main states:
Ready state: Task is ready to run but is waiting because a higher priority task is executing.
The kernel's scheduler decides when tasks change states, prioritizing higher-priority tasks. State
changes can lead to context switches, where a new high-priority task starts executing and the previous
one may get blocked or enter the ready state.
* a typical finite state machine for task execution
1.READY STATE
• In the ready state, tasks compete for processor time. They cannot directly
move to the blocked state but must first run and make a blocking call to
enter that state.
• The kernel's scheduler uses task priorities to determine which task moves
to the running state.
• For kernels supporting one task per priority level, the highest priority task
runs next. However, most kernels support multiple tasks per priority level,
using a task-ready list for scheduling.
• This list organizes tasks by priority, with the highest priority task running
first.
.
• Tasks in the running state are actively executing.
• A running task can return to the ready state while it's still running if
preempted by a higher priority task. The preempted task is placed back in
the task-ready list based on its priority, while the higher priority task takes
its place in the running state.
• A running task can transition to the blocked state in several ways:
• Without blocked states, lower priority tasks wouldn't get a chance to run,
leading to CPU starvation where higher priority tasks consume all CPU
time.
• A task enters the blocked state by making a blocking call, waiting for a
specific condition to be met.
.
• When a blocked task becomes unblocked, it may transition to the ready
state if it's not the highest priority.
• It's then placed in the task-ready list based on priority. However, if the
unblocked task is highest priority, it moves directly to the running state,
preempting the current task.
• The preempted task then goes back to the ready state based on its
priority
TYPICAL TASK OPERATION
• Kernels offer task-management services that operate behind the scenes,
supporting tasks by creating and maintaining Task Control Blocks (TCBs)
and task stacks.
- Creating and deleting tasks: Developers can create new tasks as needed
and remove them when they're no longer required.
-Controlling task scheduling: This involves managing task priorities,
scheduling policies, and task states to optimize system performance.
Operation Description
Get ID Get the current task's ID
• For example, developers can use the Get ID operation to obtain a task's ID,
which can then be used to retrieve more detailed information about the task
by accessing its TCB.
pseudo RunToCompletionTask()
{
Initialize application
Create 'endless loop tasks'
Create kernel objects
Delete or suspend this task
}
• The application initialization task typically has a higher priority
than the tasks it creates to ensure that its initialization work is not
preempted.
pseudo EndlessLoopTask_()
{
Initialization code
Loop Forever
{
Body of loop
Make one or more blocking call
}
}
• The crucial aspect of an endless-loop task design is the
presence of one or more blocking calls within the loop body.
• The fundamental construct for most kernels is the task object, which,
along with task-management services, enables developers to design
applications for concurrency, meeting multiple time constraints and
addressing synchronization and communication challenges.
CONCLUSION
1. Real-time kernels offer task objects and task-management services to
meet the needs of real-time applications.
4. Tasks can be in one of three primary states: ready, running, and blocked.
5. Priority-based preemptive scheduling is commonly used in real-time
kernels, with task-ready lists helping schedule multiple tasks.