A Task is simply a set of instructions that can be suspended and resumed at any point within that set. A function could also be thought of as a set of instructions, and hence tasks can be seen as something similar. But there are two crucial differences—one, there is no overhead to switching between one task to another, meaning, no stack space is reserved for a switch. Second, unlike a function that has to finish before control goes back to the caller, a task can be interrupted and control switched to another at many different times during its execution. In other words, there is no caller-callee hierarchical relationship in tasks.Â
Tasks can provide the illusion of having two parallel sequences of instructions running simultaneously on the computer. It is important to note that with tasks, only one of those sequences is running on the CPU at any one point. Tasks...