Preemptive multitasking is a method of running several programs concurrently in which the operating system kernel decides when a task loses the processor, interrupting it without its cooperation and switching to another ready task. In the field of Processes & scheduling, it is the model used by every mainstream desktop, server and mobile operating system, including Windows NT and its successors, Linux, macOS and the BSD family.
The defining property is involuntary removal from the CPU. A task does not need to call a yield function or wait for input before another task can run; a hardware timer interrupt or a higher-priority event returns control to the kernel, which may then select a different thread. This guarantees that no single program can monopolize the processor, which is the main reason modern systems stay responsive even when an application hangs.
How the kernel takes the processor back
The kernel regains control through interrupts that the running task cannot block. The most important source is a programmable hardware timer, such as the local APIC timer on x86 processors or the generic timer on ARM, which fires periodically or at a precisely programmed deadline. When the interrupt arrives, the processor switches to kernel mode and runs the scheduler logic.
The scheduler then checks whether the current thread has exhausted its time slice or whether a higher-priority thread has become ready. If either is true, the kernel performs a context switch: it saves the registers, program counter and stack pointer of the current thread, loads the saved state of the chosen thread and returns to user mode. The sequence of events is summarized below.
| Step | What happens | Who performs it |
|---|---|---|
| Timer fires | Hardware raises an interrupt at the end of the quantum | Timer hardware |
| Mode switch | CPU enters kernel mode and saves minimal state | Processor |
| Accounting | Kernel charges elapsed time to the running thread | Kernel |
| Scheduling decision | Scheduler picks the next thread from the run queue | Kernel scheduler |
| Context switch | Registers and address space of the new thread are loaded | Kernel |
| Resume | New thread continues in user mode | Processor |
Preemption is not caused only by the timer. When a device interrupt wakes a blocked thread with a higher priority, for example a thread waiting for keyboard input, the kernel can preempt the current thread immediately instead of waiting for the slice to expire. This is why interactive latency stays low even under heavy background load.
Key parameters that shape preemptive behavior
The behavior of a preemptive system depends on a handful of tunable scheduler parameters. Their values differ between operating systems and workloads, and the ranges below are typical rather than fixed.
| Parameter | Typical range | What it affects |
|---|---|---|
| Time slice length | About 1 to 100 ms | Responsiveness versus switching overhead |
| Timer frequency | 100 to 1000 Hz, or tickless | Granularity of scheduling decisions |
| Context switch cost | Roughly 1 to 10 microseconds | Share of CPU time lost to switching |
| Priority levels | 32 in Windows, 140 in Linux | How finely urgency can be expressed |
| Kernel preemption model | None, voluntary or full | Latency inside system calls |
Many current kernels are tickless: instead of interrupting at a fixed rate, they program the timer for the next needed event. This reduces power consumption on idle cores while keeping preemption precise when work is present. A separate question is whether the kernel itself is preemptible. Linux offers configurations ranging from no forced kernel preemption to fully preemptible kernels and the PREEMPT_RT patch set for real-time use.
Preemptive compared with cooperative multitasking
The clearest way to understand preemptive multitasking is to contrast it with cooperative multitasking, in which a task keeps the CPU until it voluntarily yields. Classic Mac OS before version X and 16-bit Windows 3.x used the cooperative model, and one misbehaving program could freeze the entire system.
| Aspect | Preemptive multitasking | Cooperative multitasking |
|---|---|---|
| Who triggers a switch | Kernel, via interrupts | Running task, via yield |
| Effect of an infinite loop | Other tasks keep running | Whole system stalls |
| Synchronization needs | Locks required almost everywhere | Fewer races between yield points |
| Latency guarantees | Bounded by slice and priority | Depends on program discipline |
| Typical use today | General-purpose operating systems | Coroutines, async runtimes, small firmware |
The trade-off is that preemption makes concurrency bugs more likely. Because a thread can be interrupted between any two instructions, shared data must be protected with mutexes, atomic operations or other synchronization. Cooperative designs avoid some of these races but shift the burden of fairness onto every program author.
Scheduling policies built on preemption
Preemption is a mechanism, while the scheduling policy decides which thread runs next. Several well-known policies depend on the ability to interrupt a running thread. Round-robin scheduling rotates threads of equal priority through fixed quanta, priority scheduling always runs the highest-priority ready thread, and a multilevel feedback queue moves threads between queues based on observed behavior so that I/O-bound processes receive quick service.
Linux used the Completely Fair Scheduler for many years and replaced it with the EEVDF scheduler in version 6.6, both of which track virtual runtime rather than fixed slices. Windows uses a priority-based preemptive scheduler with dynamic boosts for foreground and I/O-completing threads. Real-time classes such as SCHED_FIFO and earliest deadline first variants preempt ordinary threads unconditionally.
Limitations, risks and common misconceptions
Preemptive multitasking solves fairness and responsiveness but introduces its own failure modes. Experienced engineers watch for the following symptoms, which are summarized with their usual causes and remedies.
| Symptom | Likely cause | Typical remedy |
|---|---|---|
| Data corruption under load | Race condition on shared state | Add locking or atomic operations |
| High-priority task stalls | Priority inversion on a lock | Priority inheritance protocols |
| Low-priority task never runs | Starvation by busy threads | Aging or fair-share scheduling |
| Throughput drops with many threads | Excessive context switching | Fewer threads or longer slices |
| Audio or video glitches | Non-preemptible kernel sections | Preemptible or real-time kernel |
- Preemption is not parallelism: on a single core, tasks still run one at a time, only interleaved.
- More threads do not mean more speed: beyond the number of cores, extra threads mostly add switching cost.
- Disabling interrupts is not a general lock: it fails on multiprocessor systems and harms latency.
The short version
Imagine a teacher who gives each student a few seconds to speak and then politely moves on to the next one, whether or not the first student has finished. Nobody can talk forever, and everyone gets a turn.
Preemptive multitasking works the same way inside a computer. The operating system gives each program a very short turn on the processor and then takes it back. Because the turns are so short, all programs seem to run at once, and a frozen program cannot freeze the whole computer.
Where it makes a difference
A data analyst runs a long statistical calculation on a four-core laptop. The job starts eight worker threads that each try to use the CPU at full speed for twenty minutes. At the same time, the analyst wants to answer messages, browse documentation and join a video call.
Because the operating system uses preemptive multitasking, the timer interrupt returns control to the kernel every few milliseconds. The scheduler gives the interactive threads of the video call a priority boost when their audio buffers need refilling, so they preempt the calculation threads immediately. The call stays smooth, the mouse pointer never freezes and the calculation finishes only slightly later than it would on an idle machine.
On a cooperative system from the early 1990s, the same calculation would have held the processor until it yielded, and the entire desktop would have appeared frozen for long periods.