Multitasking

Multitasking (also refered to as "multiprogramming", "concurrent processing", "concurrency", or "process scheduling") is a technique used in an operating system for sharing a single processor between several independent jobs. The first multitasking operating systems (such as Unix) were designed in the 1960s.

Cooperative multitasking
Under cooperative multitasking, the running task decides when to give up control of the CPU. This method was first implemented in classic Mac OS by Andy Hertzfeld's Switcher as early versions of the Macintosh operating system were designed with little provision for any multitasking, besides simple desk accessories. Switcher evolved into the MultiFinder and then became an integral part of System 7. The drawback of cooperative multitasking is that one buggy application can cause a system error that locks up and crashes the computer entirely.

Pre-emptive multitasking
Under pre-emptive multitasking (now more common), a system process called the "scheduler" suspends the currently running task after it has run for a fixed period known as a "time-slice". In both cases the scheduler is responsible for selecting the next task to run and (re)starting it. The running task may also relinquish control voluntarily even in a pre-emptive system if it is waiting for some external event. This more stable form of multi-tasking was partially implemented with the new nanokernel of Mac OS 8.6, causing errant applications to "unexpectedly quit" instead of crashing the entire system. Mac OS X (now macOS) and its derivatives, such as iOS, were designed around pre-emptive multitasking and are better equiped to isolated such problems. Running processes can be inspected through the Activity Monitor.

In either of the above systems, a task may be suspended prematurely if a occurs, especially if a higher priority task was waiting for this event and has therefore become runnable.

Scheduling
The algorithm used by the scheduler determines which task will run next. Some common examples are round-robin scheduling, priority scheduling, shortest job first and guaranteed scheduling. Multitasking introduces some overhead because the processor is required to spend some time in choosing the next job to run and in saving and restoring tasks' state, but it reduces the worst-case time from job submission to completion compared with a simple batch system where each job must finish before the next one starts. Multitasking also means that while one task is waiting for some external event, the CPU can do useful work on other tasks.

Protection
A multitasking operating system should provide some degree of memory protection of one task from another to prevent tasks from interacting in unexpected ways such as accidentally modifying the contents of each other's memory areas. The jobs in a multitasking system may belong to one or many users. This is distinct from parallel processing where one user runs several tasks on several processors. Time-sharing is almost synonymous but implies that there is more than one user.

Multithreading is a type of multitasking with low overhead and no protection of tasks from each other, all threads share the same memory.

Articles

 * Difference between Preemptive and Cooperative Multitasking at GeeksforGeeks (2020-04-28)
 * How to Use Multitasking on the iPhone by Sam Costello at Lifewire (2020-03-11)
 * iPad multitasking still stinks after 10 years — here’s how Apple could fix it by Jeremy Horwitz at VentureBeat (2020-03-27)