# Cooperative multitasking

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Cooperative_multitasking
> Markdown URL: https://mediated.wiki/source/Cooperative_multitasking.md
> Source: https://en.wikipedia.org/wiki/Cooperative_multitasking
> Source revision: 1330479161
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Computer multitasking that does not preempt processes

**Cooperative multitasking**, also known as **non-preemptive multitasking**, is a [computer multitasking](/source/Computer_multitasking) technique in which the [operating system](/source/Operating_system) never initiates a [context switch](/source/Context_switch) from a running [process](/source/Process_(computing)) to another process. Instead, in order to run multiple applications concurrently, processes voluntarily [yield control](/source/Yield_(multithreading)) periodically or when idle or logically [blocked](/source/Blocking_(computing)). This type of multitasking is called *cooperative* because all programs must cooperate for the scheduling scheme to work.

In this scheme, the [process scheduler](/source/Process_scheduler) of an operating system is known as a **cooperative scheduler** whose role is limited to starting the processes and letting them return control back to it voluntarily.[1][2]

This is related to the [asynchronous programming](/source/Asynchronous_programming) approach.

## Usage

Although it is rarely used as the primary scheduling mechanism in modern operating systems, it is widely used in memory-constrained [embedded systems](/source/Embedded_system) and in specific applications such as [CICS](/source/CICS) or the [JES2](/source/JES2) subsystem. Cooperative multitasking was the primary scheduling scheme for 16-bit applications employed by [Microsoft Windows](/source/Microsoft_Windows) before [Windows 95](/source/Windows_95) and [Windows NT](/source/Windows_NT), and by the [classic Mac OS](/source/Classic_Mac_OS). [Windows 9x](/source/Windows_9x) used non-[preemptive multitasking](/source/Preemptive_multitasking) for 16-bit legacy applications, and the [PowerPC](/source/PowerPC) Versions of Mac OS X prior to [Leopard](/source/Mac_OS_X_v10.5) used it for [classic](/source/Classic_(Mac_OS_X)) applications.[1] [NetWare](/source/NetWare), which is a network-oriented operating system, used cooperative multitasking up to NetWare 6.5. Cooperative multitasking is still used on [RISC OS](/source/RISC_OS) systems.[3]

Cooperative multitasking is similar to [async/await](/source/Async%2Fawait) in languages, such as [JavaScript](/source/JavaScript) or [Python](/source/Python_(programming_language)), that feature a single-threaded event-loop in their runtime. This contrasts with cooperative multitasking in that await cannot be invoked from a non-async function, but only an async function, which is a kind of [coroutine](/source/Coroutine).[4][5]

Cooperative multitasking allows much simpler implementation of applications because their execution is never unexpectedly interrupted by the process scheduler; for example, various [functions](/source/Subroutine) inside the application do not need to be [reentrant](/source/Reentrancy_(computing)).[2]

## Problems

As a cooperatively multitasked system relies on each process regularly giving up time to other processes on the system, one poorly designed program can consume all of the CPU time for itself, either by performing extensive calculations or by [busy waiting](/source/Busy_wait); both would cause the whole system to [hang](/source/Hang_(computing)). In a [server](/source/Server_(computing)) environment, this is a hazard that is often considered to make the entire environment unacceptably fragile,[1] though as noted above, cooperative multitasking has been used frequently in server environments, including NetWare and CICS.

In contrast, [preemptive](/source/Preemption_(computing)) multitasking interrupts applications and gives control to other processes outside the application's control.

The potential for system hang can be alleviated by using a [watchdog timer](/source/Watchdog_timer), often implemented in hardware; this typically invokes a [hardware reset](/source/Hardware_reset).

## See also

- [Consensus dynamics](/source/Consensus_dynamics)

## References

1. ^ [***a***](#cite_ref-pcmag_1-0) [***b***](#cite_ref-pcmag_1-1) [***c***](#cite_ref-pcmag_1-2) ["Definition of non-preemptive multitasking"](https://www.pcmag.com/encyclopedia/term/48051/non-preemptive-multitasking). *pcmag.com*. Retrieved August 15, 2015.

1. ^ [***a***](#cite_ref-classiccmp_2-0) [***b***](#cite_ref-classiccmp_2-1) Joe Bartel (November 5, 2011). ["Non-Preemptive Multitasking"](https://web.archive.org/web/20190819072905/http://www.classiccmp.org/cini/pdf/HT68K/HT68K%20TCJ30p37.pdf) (PDF). *classiccmp.org*. Archived from [the original](http://www.classiccmp.org/cini/pdf/HT68K/HT68K%20TCJ30p37.pdf) (PDF) on August 19, 2019. Retrieved August 15, 2015.

1. **[^](#cite_ref-3)** ["Preemptive multitasking"](http://www.riscos.info/index.php/Preemptive_multitasking). *riscos.info*. November 2, 2009. Retrieved August 15, 2015.

1. **[^](#cite_ref-4)** Kerkour, Sylvain (January 25, 2022). ["Async Rust: Cooperative vs Preemptive scheduling"](https://kerkour.com/cooperative-vs-preemptive-scheduling). Retrieved January 30, 2023.

1. **[^](#cite_ref-5)** Skvortsov, Victor. ["Python behind the scenes #12: How async/await works in Python"](https://tenthousandmeters.com/blog/python-behind-the-scenes-12-how-asyncawait-works-in-python/). Retrieved January 30, 2023.

v t e Operating systems General Comparison Forensic engineering History List Timeline Usage share User features comparison Variants Disk operating system Distributed operating system Embedded operating system Hobbyist operating system Just enough operating system Mobile operating system Network operating system Object-oriented operating system Real-time operating system Supercomputer operating system Kernel Architectures Exokernel Hybrid Microkernel Monolithic Multikernel vkernel Rump kernel Unikernel Components Device driver Loadable kernel module User space and kernel space Process management Concepts Computer multitasking (Cooperative, Preemptive) Context switch Interrupt IPC Process Process control block Real-time Thread Time-sharing Scheduling algorithms Fixed-priority preemptive Multilevel feedback queue Round-robin Shortest job next Memory management, resource protection Bus error General protection fault Memory paging Memory protection Protection ring Segmentation fault Virtual memory Storage access, file systems Boot loader Defragmentation Device file File attribute Inode Journal Partition Virtual file system Virtual tape library Supporting concepts API Computer network HAL Live CD Live USB Shell CLI User interface PXE

---
Adapted from the Wikipedia article [Cooperative multitasking](https://en.wikipedia.org/wiki/Cooperative_multitasking) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Cooperative_multitasking?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
