Course contentsShow
← Computer Science
Lesson 2547 of 2,87257. Concurrency FundamentalsFree lesson

Single-Core Concurrency Through Time-Slicing

Explore how concurrent programs run on single-core systems by rapidly switching between tasks through context switching.

Single-Core Concurrency Through Time-Slicing

What you'll learn: How a single CPU core creates the illusion of running multiple tasks simultaneously by rapidly switching between them.

The Core Idea

On a single-core system, only one instruction can truly execute at any given instant. Yet your computer appears to run dozens of programs at once—music playing, browser open, chat app active. This magic happens through time-slicing: the operating system rapidly switches the CPU's attention between tasks, giving each a tiny slice of time (often milliseconds) before moving to the next.

Think of it like a chef cooking multiple dishes. They can't stir two pots simultaneously with one hand, but by stirring pot A for a few seconds, then pot B, then checking pot C, and cycling back—all dishes progress toward completion. To an observer, it looks like everything's cooking "at once."

Context Switching: The Mechanism

When the OS switches from Task A to Task B, it performs a context switch:

  1. Save state: Store Task A's current instruction pointer, register values, and memory state
  2. Load state: Restore Task B's previously saved state
  3. Resume: Task B continues exactly where it left off

This happens so quickly (thousands of times per second) that users perceive smooth, concurrent operation—even though execution is strictly sequential at the hardware level.

The Concurrency Illusion

Time-slicing enables concurrency (dealing with multiple tasks) without requiring parallelism (doing multiple tasks simultaneously). Tasks make progress over time by interleaving their execution, but only one actually runs at each moment.

The cost? Context switching overhead—saving and restoring state takes CPU cycles. If tasks switch too frequently, more time goes to switching than actual work.

Key Takeaway: Single-core concurrency uses time-slicing and context switching to rapidly alternate between tasks, creating the illusion of simultaneous execution without true parallel hardware.