Main Content

What is Task Execution?

A task is a unit of execution or unit of work in a software application. Typically, task execution in an embedded processor is managed by the operating system (OS). When deployed to the embedded processor, a task corresponds to an OS thread.

Task Execution Life Cycle

The life cycle of a task can be divided into five states:

  • Created – The system creates all the tasks when the application starts and immediately moves them to the waiting state.

  • Waiting – The task waits for the associated trigger signal, such as an OS timer or I/O device. After receiving the trigger signal, the task starts to run. If the task has the highest priority, it enters the running state. Otherwise, the task continues to wait until it becomes the highest priority, triggered task.

  • Running – The task executes its code. When the code completes execution, the task immediately moves to the waiting state. If a trigger for a higher-priority task occurs, the running task moves to the preempted state.

  • Preempted – The task is preempted and waiting to run. A task runs based on a combination of the task priority and the order the task entered the Preempted state. Assuming equal task priorities of all other tasks in Ready to Resume state, tasks run based on first-in-first-out (FIFO) ordering.

  • Terminated – Tasks terminate when the application ends.

This figure shows the state diagram of a task execution life cycle for an application using an OS. For simplicity, the terminated state is not shown, but a task can reach the terminated state from any of the other states.

Task life cycle state diagram

Task and Thread

A task is a conceptual unit of work in an algorithm. In an application executing on a device, a task is a section of code that executes in a thread within an operating system (OS). The OS thread determines the state of execution of the task. When deployed to hardware, an OS thread uses the task properties. The thread executes the code generated from the subsystem. Conceptually, a Task in simulation is equivalent to a thread in generated code.

See Also

Related Topics

External Websites