01
Concurrency Models
What the global interpreter lock restricts, threads for I/O-bound work, multiprocessing for CPU-bound work, the event loop and coroutines, moving blocking code out of an asynchronous flow, and distributing work through a common interface.
- 01 The Global Interpreter Lock This course counts overlapping steps, not duration; in an eighty-step setup, a single thread gives 80 ticks and 0 overlapping steps on every load, a single-slot regime takes at most 1 CPU step per tick, and the I/O-bound load's 26 CPU steps spread across 26 separate ticks.
- 02 Threads Eight workers and a single slot finish eighty steps in 31 ticks on the I/O-bound load (gain 49, ratio 0.6125), and only 73 ticks on the CPU-bound load (gain 7); same mechanism, a sevenfold difference, and the gain is bounded in every load by the number of steps that can overlap.
- 03 Multiprocessing Four slots drop the CPU-bound load's eighty steps to 20 ticks (gain 60); at eight slots, all three loads give 10 ticks and 70 overlapping steps; against that, adding 15 transfer steps to each task at both ends drops four slots' gain from 60 ticks to 0.
- 04 Asynchronous Programming The source of overlap is not the operating system, it is the code itself: a coroutine that gives up control before every step gives 31 ticks and 49 overlapping steps with 80 yields, one that gives up control only at I/O steps gives 36 ticks and 44 overlapping steps with 54 yields, and one that never gives up control gives 80 ticks and 0 overlapping steps with 0 yields.
- 05 Asynchronous Library Compatibility One blocking call in every task drops overlapping steps from 44 to 37, and when seven of eight tasks block, overlap drops to 0 despite 6 yields; offloading the call to an executor pool restores overlap to 44, but whether the cost falls once per task or once per call splits tick count between 44 and 90.
- 06 Executor Pools The same interface finishes the same task on two backends with separate numbers: at width eight, a thread pool gives 31, 42, and 73 ticks across the three loads, while a process pool gives 10 ticks and 70 overlapping steps on all three; the interface being the same does not mean the choice is the same.