Multitasking

TODO: Explain more in-depth

Processes vs. Threads

In short: A process is an abstract type of a task that has it's own address space, while a thread has their own registers and stack.

TODO: Explain more in-depth

Context Switches

A context switch is done when all registers are loaded from storage (the state) into the current registers, this also includes switching address spaces (if paging is used) by pointing to a new root page table, which can be or not saved in the state along with the registers.

In some architectures extra space is required to save the state of vector registers, for example in x86, the SSE instructions uses about 256-bytes to save the vector registers on a state.

Context switches are costly; however running 1 process while it's doing nothing for a prolonged time may result to be a very bad latency. Various algorithms exist for this task:

Round robin scheduling

Basic form of scheduling, go to next process and when we are at the tail process we go back to the head.

*NIX scheduling

So we are going to punish processes who use more CPU time!

Priority scheduling

Some processes have more priority than others, processes with similar priority can be handled by an algorithm to sort them.

Threads, Tasks and Jobs

A thread can be viewed as a person doing a work (let's say, cultivate rice), a task can be tought as the farm where they cultivate, and a job is the locality where they live.

Threads mostly have their own stack but share their parent task heap, they also have their own register contextes and program counter.

Tasks will have their own heap and usually their list of threads.

Jobs can hold many tasks which will run sequentially or parallel if you wish.