liveBook · Manning

Time slice

As explained in Grokking Concurrency

A time slice is a bounded interval during which a scheduled task is allowed to execute on a processor before potentially being preempted.

Think of a processor as a single arcade machine shared by several players. A time slice is the bounded interval in which the operating system lets one scheduled task use the CPU before the scheduler may pause it and give another task a turn. section 6.7

During its slice, a task in the Ready state runs unless it performs a blocking operation. When the interval expires, a timer interrupt lets the scheduler preempt the task; the task waits while another runs. section 6.7

Time slices create the experience of multitasking through rapid switching:

  • The scheduler divides available processor time among running tasks. section 6.7
  • A timer signals the end of a slice and pauses the current task. section 6.8
  • Fast interleaving produces concurrent progress even when one processor executes only one task at a time. section 6.8

An arcade machine shared by threads

An arcade-style runtime gives each thread an equal time slice, then passes control to the next thread. With switching around every 10 milliseconds, players perceive simultaneous game activity even though the processor is rapidly executing tasks in turn. section 6.8

Trace task progress across time to see how repeated slices and scheduler switches create the appearance of simultaneous execution. section 6.7

How Grokking Concurrency covers it

How deep it goes
Defines slices, ready tasks, timer interrupts, and preemption, but stops short of detailed scheduler implementation.
Examples
Uses an arcade machine, multiple game threads, timer ticks, and rapid interleaving as concrete examples.
What it assumes
Introduces CPU sharing, task states, interrupts, and preemption without requiring prior operating-system knowledge.
What you can do after
Understand how rapid CPU switching produces concurrent progress without requiring physically simultaneous execution.
How it connects
Connects time slices to preemptive multitasking, time-sharing, interrupts, schedulers, concurrency, and parallelism.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.