liveBook · Manning

Task switching

As explained in C++ Concurrency in Action, Second Edition

A scheduling technique in which a processor alternates execution among tasks, running part of each in turn.

Task switching lets a single-core processor appear to run multiple tasks concurrently by executing a portion of one, then switching to another. This is an illusion of concurrency, unlike multiple tasks running in parallel on separate cores. section 1.1.1

Figure 1.1. Two approaches to concurrency: parallel execution on a dual-core machine versus task switching on a single-core machine

Compare task switching on a single core with parallel execution on two cores. section 1.1.1

When a system has more threads than cores, switching threads can increase cache pressure. If a thread moves between cores, its cache lines may also need to be transferred, adding performance costs. section 8.2.4

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Defines task switching and flags memory-model risks, while deferring their deeper treatment.
Examples
Uses a single-core desktop running multiple applications and threads switching among cores as examples.
What you can do after
Understand how thread switching and migration can increase cache reloads and data-transfer costs.
How it connects
Links task switching to concurrency, parallelism, memory models, cache lines, and false sharing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.