01

Chapter 01 — The Four Execution Models, Counted

Concurrency (structure) and parallelism (execution) are independent axes, so crossing them produces four real execution models, counted with observables instead of timed.

Demo 01Source on GitHub ↗

The full source for this example lives in examples/concurrency/01-execution-models/ — clone the repo, cd in, and ./demo.sh.

Chapter reference: Doc 1 — Concurrency vs Parallelism

What it shows

The same instrumented workload runs under four models — sequential, concurrent-but-pinned-to-one-CPU, parallel-with-no-visible-threads, and an oversubscribed thread pool — and reports three counted observables per model: how many distinct CPUs it actually touched, the peak number of overlapping tasks, and how often two tasks’ own sample points interleaved. That is the chapter’s point made mechanical: concurrency (structure) and parallelism (execution) are independent, so “looks concurrent” and “ran in parallel” need separate proof. A Lua harness checks the sequential and concurrent-pinned cases as hard, environment-independent facts, and treats cross-CPU parallelism as a soft signal when the container’s cpuset offers too few cores to show it.

Running it

cd examples/concurrency/01-execution-models
./demo.sh            # build + run execution_models + verify.lua
./demo.sh --clean    # remove the image