preemptive multitasking
Preemptive multitasking is a CPU scheduling approach in which the operating system can interrupt a running task and hand the CPU to another, without the task’s cooperation. A component called the scheduler decides which task runs next and forces the switch on its own schedule.
The mechanism rests on a hardware timer that fires an interrupt at regular intervals. Each task gets a small slice of CPU time, called a time slice or quantum.
When the slice expires, the timer interrupt suspends the current task, the scheduler picks another runnable task, and a context switch saves the old task’s state and restores the new one. The interrupted task resumes later from exactly where it left off, and the whole cycle repeats on the next timer tick:
Capping how long any single task can hold the CPU keeps the whole system responsive. A task that gets stuck in a loop or a blocking call can’t freeze everything else, unlike under cooperative multitasking, which relies on each task to yield voluntarily. Preemptive multitasking underpins Windows, macOS, and Linux, along with the time-sharing of threads within a process.
Related Resources
Tutorial
Speed Up Your Python Program With Concurrency
In this tutorial, you'll explore concurrency in Python, including multi-threaded and asynchronous solutions for I/O-bound tasks, and multiprocessing for CPU-bound tasks. By the end of this tutorial, you'll know how to choose the appropriate concurrency model for your program's needs.
For additional information on related topics, take a look at the following resources:
- An Intro to Threading in Python (Tutorial)
- What Is the Python Global Interpreter Lock (GIL)? (Tutorial)
- Python Thread Safety: Using a Lock and Other Techniques (Tutorial)
- Python 3.13: Free Threading and a JIT Compiler (Tutorial)
- Python 3.14 Release Candidate Lands: Faster Code, Smarter Concurrency (Tutorial)
- Hands-On Python 3 Concurrency With the asyncio Module (Course)
- Speed Up Python With Concurrency (Course)
- Python Concurrency (Quiz)
- Threading in Python (Course)
- Python Threading (Quiz)
- Understanding Python's Global Interpreter Lock (GIL) (Course)
- What Is the Python Global Interpreter Lock (GIL)? (Quiz)
- Thread Safety in Python: Locks and Other Techniques (Course)
- Python Thread Safety: Using a Lock and Other Techniques (Quiz)
- Python 3.13: Free Threading and a JIT Compiler (Quiz)