Multitasking
What Is Multitasking?
Multitasking is the capability of a computing system to manage multiple tasks concurrently, interleaving their execution so that each appears to progress simultaneously from the perspective of users or application logic. On a single-processor system, true simultaneity is impossible; instead, the operating system rapidly switches the processor among tasks, creating the illusion of parallel execution. On multi-core and multi-processor systems, tasks can execute in genuine parallel on separate cores while still requiring coordination through shared memory and synchronization primitives. Multitasking is fundamental to modern operating systems, embedded controllers, and real-time applications.
Preemptive Scheduling
In preemptive multitasking, the operating system retains control over when a task must yield the processor. A hardware timer generates periodic interrupts; the scheduler runs at each interrupt and may elect to suspend the currently executing task and dispatch a higher-priority or time-sliced candidate. This preemptive model prevents any single poorly behaved task from monopolizing the processor indefinitely.
Scheduling algorithms vary in their optimization targets. Round-robin scheduling gives each task an equal time slice in sequence, providing fairness but not differentiation by urgency. Priority-based preemptive scheduling runs the highest-priority ready task first, benefiting real-time workloads where certain tasks have deadlines. Completely Fair Scheduler (CFS), used by the Linux kernel, maintains a virtual runtime per task and always dispatches the task with the smallest accumulated runtime, achieving fairness without fixed time slices. Linux kernel scheduling documentation explains the red-black tree data structure CFS uses to select the next task in O(log n) time.
Thread Management
Operating systems implement multitasking at two levels: processes and threads. A process is an isolated execution context with its own virtual address space. A thread is a lighter-weight execution unit that shares the address space of its parent process. Multiple threads within a process can execute concurrently, sharing data structures without the overhead of inter-process communication. Thread management requires synchronization mechanisms including mutexes, semaphores, and condition variables to prevent data races when threads access shared state. POSIX thread programming documentation defines the standard API for thread creation, synchronization, and termination used across Unix-like operating systems.
Priority inversion is a classic hazard in multitasking systems: a high-priority task blocks waiting for a resource held by a low-priority task, while medium-priority tasks preempt the low-priority holder and prevent it from releasing the resource. Priority inheritance protocols address this by temporarily elevating the priority of the resource-holding task.
Real-Time Multitasking
Real-time operating systems (RTOS) extend multitasking with deterministic scheduling to guarantee that time-critical tasks meet their deadlines. Hard real-time systems, found in flight control, medical devices, and industrial automation, treat a missed deadline as a system failure. Soft real-time systems, typical of multimedia playback and telecommunications, tolerate occasional deadline misses with graceful quality degradation. Research on real-time scheduling theory provides schedulability analysis tools such as rate-monotonic scheduling and earliest-deadline-first, which determine whether a given set of periodic tasks can all meet their deadlines on a processor with bounded utilization.
Interrupt latency, the time between an external event and the start of its handler, must be bounded and minimized in real-time systems. RTOS designs achieve this through non-maskable interrupt paths, priority inheritance, and short critical sections.
Applications
- Desktop operating systems: Multitasking allows users to run web browsers, document editors, and media players simultaneously without waiting for each to complete before launching the next.
- Web servers: Concurrent thread and process pools handle thousands of simultaneous HTTP requests, multiplexing network I/O with application logic across available cores.
- Industrial control: Programmable logic controllers and RTOS-based embedded systems execute sensor reading, control calculation, and actuator output tasks in precisely timed cycles.
- Telecommunications: Base station software manages simultaneous radio signal processing, protocol stack execution, and backhaul communication through carefully scheduled real-time tasks.
- Automotive systems: Engine control units interleave fuel injection timing, ignition control, emission monitoring, and fault logging tasks within microsecond-scale scheduling windows.
- Cloud computing: Hypervisors multiplex dozens of virtual machines across physical server cores, managing CPU, memory, and I/O resources through preemptive scheduling at the hardware level.