Context switching alternates execution among threads. On a single CPU, rapid switching enables concurrency; across multiple cores, threads can also execute in parallel. section 16.1
Dinner-party analogy
One person switching among cleaning, cooking, and setting the table models concurrency. Friends handling separate tasks model parallelism, while shared utensils require synchronization and mutual exclusion. section 16.1
Switching threads is not free. Mutexes, semaphores, condition objects, and context-switching costs can overwhelm the benefit of adding threads, while timing can make behavior difficult to reproduce and debug. section 16.5
Figure 16.1 A multithreaded application with three threads. The threads share the application’s internal resources of code and data in memory and external resources such as printers and files. The runtime system gives each thread its own runtime stack and the appearance of having its own set of machine registers.
Use the figure to inspect how threads share code, data, and external resources while retaining separate runtime stacks and apparent machine registers. section 16.1








