Threads

A thread is the minimal unit of execution in an RTOS.

Is a sequence of steps for doing some specific job, thus is a program.

As any other program, it has an start address and an end address and a program counter (aka PC, used to know in what line of code we are executing at some determined time).

Each thread has it's own stack pointer and stack space.

In a RTOS sytem, each thread has an status. The status of a thread is a set of thread properties such as: stack pointer, PC, start address, end address, thread flags, processor registers and control registers. The thread status is also known as "context".

The space in memory used to store the context of a thread is named "Thread Control Block" or TCB. Aka "thread object" or "context space".

Once we save a thread's context we are able to stop running this thread and start running it again at a later time (by loading its registers and stacks, and continuing from the last PC saved)

In a RTOS system, each thread also has a priority. Threads with higher priority will have more privilege to use the processor than threads with lower priority.

A set of threads makes an application or process. Process is not an RTOS concept, is more a multi-purpose OS concept.

Threads in an RTOS systems are not supposed to finish or are rarely finished. Thus, when a thread completes its execution it is known as done or terminated

Depending the RTOS is the number of states a thread can be. The most common states are shown here: