Cooperative multitasking
Multitasking describes a mechanism that lets a single CPU core serve multiple tasks concurrently. There are multiple ways to implement multitasking. A key distinction can be made between preemptive multitasking and cooperative multitasking. In preemptive multitasking, a higher-level authority such as the OS decides how long a given task can use the system’s resources (such as the CPU) before they are given to another task. This is especially useful when a lot of different tasks run on a large system, and not all of them can be trusted to manage their resource consumption responsibly. However, it makes the system more complex by requiring a powerful task manager that can start and stop task executions.
In cooperative multitasking, tasks are split into small steps and then served sequentially—for example, in the Arduino loop()
function. Each task only does a small amount of computation at once, requiring only a very short usage of the system...