Tasks

A task can be a simple as a single function that runs independently on its own stack. For example a simple while loop.

void Task(void)
{
    while(1)
    {
        // Do some work
    }
}

Its stack can be any block of memory as long as its available for as long as the task is running. For example a globally declared array of integers:

int taskStack[TASK_SIZE];

Task Stack

A task stack serves three purposes. The first is to support function calls. The second is as storage for local variables. The third is as storage for the task’s context when the task is not running.

Task States

  • Tasks can be in different states
  • The simplest is either running or waiting to run

Task Control block

A Task Control Block, or TCB, is really just a simple struct with fields where we can write the information we need to track multiple tasks.

  • Store the top of stack pointer when the task is not running
  • one stack and one context tracking struct per task
  • A simple structure
  • Used to keeping track of a task
  • Each task has its own task control block
  • It is used to start the task and to remember the task’s context

Table Of Contents

Previous topic

Context Switch Assignment

Next topic

Critical Sections

This Page