Multitasking & Resource Allocation (HL)
What is Multitasking?
Multitasking refers to an operating system’s ability to execute multiple processes simultaneously, optimising CPU time.
The OS must efficiently allocate CPU cycles, memory, and I/O devices to prevent conflicts and ensure smooth performance.
Challenges of Multitasking
| Challenge | Description | Solution |
|---|---|---|
| Task Scheduling | Determining the order in which processes get CPU time is crucial to multitasking efficiency. Poor scheduling can lead to unfair distribution of resources and degraded system performance. | CPU scheduling algorithms like Round Robin and Priority Scheduling help balance fairness and efficiency. |
| Resource Contention | When multiple processes try to access the same resource at the same time, contention occurs. Without careful coordination, it can result in bottlenecks and unpredictable behaviour. | The OS uses techniques such as locking mechanisms, signalling methods, and task prioritisation to control access and prevent conflicts. |
| Deadlock | Deadlock happens when two or more processes are waiting on each other to release resources, and none can proceed. This leads to system inaction or complete halts. | Deadlock prevention and detection algorithms monitor and resolve cyclic dependencies in resource allocation. |
How the OS Allocates Resources
| Resource | Allocation Strategy | Challenge Solved |
|---|---|---|
| CPU | Uses scheduling algorithms such as Round Robin and Multilevel Queue. | Optimises task execution and prevents long wait times. |
| Memory | Virtual memory, paging, and memory protection strategies. | Prevents memory overflow and allows safe multitasking. |
| Storage | File system organisation and block-level caching. | Ensures fast and reliable data access. |
| Peripheral Devices | Driver-based I/O scheduling and interrupt handling. | Efficient use of devices such as printers, keyboards, and USB ports. |
Deadlock Prevention Methods
| Method | Description |
|---|---|
| Resource Allocation Ordering | Resources must be requested in a predefined order to prevent circular waits. |
| Preemption | Allows the OS to forcibly reclaim resources from processes if needed. |
| Wait-and-Hold Avoidance | Requires processes to request all resources at once instead of waiting mid-execution. |
Scenarios: Challenges of Multitasking and Resource Allocation
Scenario 1: Task Scheduling in a Video Editing Setup
Context: A user is editing a video while streaming music, downloading a file, and browsing the internet.
Challenge: The CPU must prioritise between real-time video rendering, smooth audio playback, background downloads, and user interactions.
Problem: If scheduled poorly, the music might stutter or the video preview might lag.
Essential Understanding: Task scheduling algorithms (e.g. Round Robin, Priority Scheduling) are crucial to ensure a smooth multitasking experience.
Scenario 2: Resource Contention in a School Computer Lab
Context: Multiple students simultaneously print documents and save work to USB drives on shared lab computers.
Challenge: Shared access to limited printers and USB ports can cause delays or failures if not managed.
Problem: Contention for the same resource leads to interruptions and performance bottlenecks.
Essential Understanding: The OS must use fair access controls like queues or access management to prevent collisions.
Scenario 3: Deadlock in a Multiplayer Game Engine
Context: Two game processes access shared resources, in this case network and storage resources.
Challenge: Player 1 and Player 2 are both playing an online, multi-user game. One player is saving data from a completed level; the other wants to join the game.
Player 1 – Saving Game Progress
- Step 1: Player 1 completes a level and the game saves progress to storage.
- Step 2: After saving, it tries to sync the data via the network.
- Resource Order: Storage → Network
Player 2 – Joining Multiplayer Match
- Step 1: Player 2 connects to the game server using the network.
- Step 2: It then tries to load user preferences from storage.
- Resource Order: Network → Storage
Problem: A circular wait causes a deadlock, freezing the game as neither player can proceed. Player 1 holds the resource Player 2 needs, and vice versa.
Player 1 and Player 2 blocking each other due to reversed resource locking order.
Essential Understanding: The OS can prevent deadlock using ordering rules, pre-allocation, or detection algorithms.
Scenario 4: Office Productivity – Balancing Background and Foreground Tasks
Context: A user writes a report, uploads files, receives video calls, and runs antivirus scans.
Challenge: Video calls require real-time responsiveness while background tasks (like antivirus or uploads) consume CPU and bandwidth.
Problem: If unmanaged, the user experiences lag in typing or call disruptions.
Essential Understanding: Priority levels and resource throttling ensure that critical tasks remain responsive.
Why Multitasking Matters
- Enhances Productivity: Enables users to run several applications at once, such as browsing while downloading files.
- Optimises System Resources: Efficient CPU and memory management prevents idle hardware.
- Improves Responsiveness: Ensures time-sensitive tasks like video playback or user input are handled promptly.
Key Takeaways
- The OS manages multiple tasks by coordinating and scheduling CPU time for each process.
- Challenges include task scheduling, resource contention, and deadlock, which must be managed proactively.
- Resource allocation strategies ensure fair distribution across tasks and devices.
- Multitasking boosts productivity, performance, and user experience in modern computing environments.