0% found this document useful (0 votes)
21 views28 pages

TASKS

Tasks are independent threads of execution that transition between ready, running, and blocked states based on priorities and blocking events. Kernels provide APIs for developers to manage tasks through operations like creation, scheduling, and obtaining task information.

Uploaded by

KRIPA K KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views28 pages

TASKS

Tasks are independent threads of execution that transition between ready, running, and blocked states based on priorities and blocking events. Kernels provide APIs for developers to manage tasks through operations like creation, scheduling, and obtaining task information.

Uploaded by

KRIPA K KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

TA S K S

• A TASK

• TYPICAL TASK OPERATION

• TYPICAL TASK STRUCTURE

• SYNCHRONIZATION, COMMUNICATION, AND


CONCURRENCY
INTRODUCTION
• Software programs typically execute sequentially, one instruction at a
time. But this approach isn't suitable for real-time and highly concurrent
outputs.

• To enable concurrent design, developers break down applications into


manageable units. Proper concurrent design allows system multitasking
to meet timing and performance needs for real-time systems.

• Tasks in an RTOS include definition, states, scheduling, operations,


structure, concurrency, and coordination, essential for effective real-time
system development.
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.

Blocked state: Task is waiting for a resource, an event, or a delay to end.

Running state: Task is the highest priority and is currently 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.

• When a task makes a blocking call, it moves to the blocked state,


allowing the next highest priority task from the ready list to start
running.

• This process continues based on task priorities and blocking calls.

• Overall, in a single-processor system with preemptive scheduling, tasks


transition between the ready, running, and blocked states based on
priorities and blocking events.
2.RUNNING STATE
• In a single-processor system, only one task can run at a time. When a task
moves to the running state, the processor loads its registers with the task's
context, allowing it to execute the task's instructions and manage its
associated stack.

• 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:

- Requesting an unavailable resource

- Waiting for an event to occur

- Delaying the task for a specified duration

• In each case, the task moves from running to blocked state.


3.BLOCKED STATE
• In real-time systems, the concept of blocked states is crucial to prevent
CPU starvation.

• 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.

• This condition could be releasing a semaphore token, receiving a message


in a queue, or when a time delay expires.

.
• 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.

• Additionally, kernels provide an API for developers to manage tasks directly


from within the application. Some common operations with a task object
include:

- 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.

-Obtaining task information: Developers can retrieve various details


about tasks, such as their state, priority, and execution status.

• It's essential for developers to familiarize themselves with these


operations for the chosen kernel to effectively manage tasks in
their projects.
1.TASK CREATION AND DELETION
Operation Description
Create Creates a task
Delete Deletes a task

- operations for task creation and deletion

• Typically, developers create a task with one or two operations,


depending on the kernel's API.

• Some kernels allow tasks to be created first and then started,


transitioning from a suspended state to the ready state when started.
• Hooks are useful for special initialization, status tracking, or cleanup
upon task context switches or deletion.

• Deleting tasks requires careful consideration to avoid memory or


resource leaks, as tasks can acquire resources that need proper
handling upon deletion to prevent issues like corrupt data structures or
unreleased resources.
TASK SCHEDULING
• From the time a task is created to when it's deleted, the kernel
manages task scheduling.

• While automatic scheduling is common, many kernels also


provide API calls for developers to manually control task
transitions between various states.

• Using manual scheduling, developers can suspend, resume,


delay, restart, and manage task priorities.

• They can also use preemption locks to control task preemption


in critical code sections.

• These operations are valuable for debugging, handling priority


inversions, and managing task execution in real-time systems.
Operation Description

Suspend Suspends a task


Resume Resumes a task
Delay Delays a task
Restart Restarts a task
Get Priority Gets the current task's priority
Set Priority Dynamically sets a task's priority
Preemption lock Locks out higher priority tasks from
preempting the current task
Preemption unlock Unlocks a preemption lock
OBTAINING TASK INFORMATION
Kernels offer routines for developers to access task information within their
applications

Operation Description
Get ID Get the current task's ID

Get TCB Get the current task's TCB (Task


Control Block)
• These operations are valuable for debugging and monitoring tasks.

• 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.

• However, it's important to note that obtaining a TCB provides a snapshot of


the task's context, which may change dynamically if the task is active.

• Therefore, developers should use this functionality wisely to avoid making


decisions based on potentially outdated task context information.
TYPICAL TASK STRUCTURE
• The operations provided for obtaining task information are crucial for
debugging and monitoring tasks.

• For instance, developers can use the Get ID operation to retrieve a


task's ID, which can then be leveraged to access more detailed
information via its Task Control Block (TCB).

• It's essential to understand that obtaining a TCB gives a snapshot of


the task's context, which can change dynamically if the task is active
and not suspended.

• Therefore, developers must use these functionalities judiciously to


avoid making decisions based on potentially outdated task context
information.
RUN TO COMPLETION
• A run-to-completion task is exemplified by the application-level
initialization process. This task initializes the application and creates
additional services, tasks, and necessary kernel objects.

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.

• Usually, the other tasks are lower priority endless-loop tasks.

• The application initialization task is designed to suspend or delete


itself after completing its work so that newly created tasks can
run.
ENDLESS LOOP TASK
• The structure of an endless-loop task is similar to the application
initialization task, where initialization code is executed initially.
• However, in an endless-loop task, the initialization code runs only once,
after which the task enters an endless loop.

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.

• These blocking calls can cause the endless-loop task to block,


allowing lower priority tasks to run.
SYNCHRONIZATION, COMMUNICATION, AND CONCURRENCY

• Tasks in software development synchronize and communicate using


intertask primitives, which are kernel objects facilitating synchronization
and communication between multiple threads of execution.

• Examples of such objects include semaphores, message queues,


signals, pipes, and others.

• 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.

2. Applications consist of system tasks or user-created tasks, each with a


name, unique ID, priority, Task Control Block (TCB), stack, and task routine.

3. Real-time applications are composed of multiple concurrent tasks, which


are independent threads competing for processor execution time.

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.

6. Tasks can be designed to run to completion or in endless loops.

7. Typical task operations include creation, deletion, manual scheduling,


and dynamic acquisition of task information.

8. Developers structure task code to allow tasks to block, facilitating


synchronization and communication.
THANKS

You might also like