liveBook · Manning

Time sharing

As explained in Learn Concurrent Programming with Go

A scheduling technique that lets multiple tasks share one processor by giving each task turns of execution.

Imagine several jobs competing for one processor. Instead of allowing one job to occupy the CPU until completion, the operating system gives jobs turns and switches among them. When one job waits for slow I/O, another can use the processor. section 2.1

Time sharing keeps a single CPU productive while tasks wait, improving responsiveness and allowing concurrent activity without requiring multiple cores. On multicore machines, the scheduler also assigns jobs across CPUs, so time sharing complements multiprocessing rather than replacing it. section 2.1 section 1.1

A job waiting for tape I/O

Suppose one job must read from or write to tape. Under a single-job approach, the CPU sits idle during that slow operation. With time sharing, the operating system switches to another ready job, so useful processing continues while the first job waits. section 2.1

Time sharing is useful when:

  • A task spends substantial time waiting for I/O. section 2.1
  • Several tasks need progress on one CPU core. section 1.1
  • Applications need better responsiveness while work proceeds concurrently. section 1.1
Figure 2.1 The operating system’s job states in a single-CPU system

Use the single-CPU job-state figure to trace how jobs move between running and waiting states as the operating system schedules them. section 2.1

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains I/O-driven task switching and single-core benefits, but does not detail time-slice selection or scheduler internals.
Examples
Uses jobs waiting for tape I/O and single-CPU execution states to make task switching concrete.
What you can do after
Evaluate how task switching keeps work progressing during I/O waits and improves responsiveness on single-core systems.
How it connects
Connects concurrency with operating systems, multiprocessing, CPU cores, scheduling, and I/O operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.