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