Skip to content

Volume 5 Exercise System

The exercises in Volume 5 are divided into three tiers, progressing from easy to hard, and from localized components to full systems.

Tier 1 consists of inline exercises attached to the end of each chapter. These verify individual concepts—such as identifying a data race, predicate waiting with condition_variable, or selecting the right atomic memory order. Each exercise takes 10–20 minutes to complete and requires no additional project setup.

Tier 2 comprises chapter Labs, which are the eight Labs listed on this page. Each Lab is a runnable mini-system broken down into 3–5 milestones. Every milestone has a clear interface, Catch2 tests, and acceptance criteria. Upon completion, learners should have a reusable concurrent component, rather than a collection of scattered demos.

Tier 3 is the end-of-volume Capstone project, which strings together all the components from the previous Labs to form a mini concurrent runtime.

Lab Overview

LabProject NameChapters CoveredSuggested DurationDifficultyPrerequisite Labs
Lab 0Thread Lifecyclech00–ch014–6hintermediateNone
Lab 1Bounded Queue & Sync Primitivesch02–ch048–12hintermediateLab 0
Lab 2Atomic Metrics & SPSC Ring Bufferch03–ch046–8hintermediateLab 0
Lab 2.5Concurrency Debuggingch083–4hintermediateLab 0–2
Lab 3Production-style Thread Poolch0510–14hadvancedLab 0–1
Lab 4Coroutine Scheduler & Event Loopch0612–16hadvancedLab 3
Lab 5Channel or Actor Runtimech078–12hadvancedLab 1, 4
CapstoneMini Concurrent Runtimech08–ch098–12hadvancedLab 0–5

The minimum requirement to cover the core competency curve of Volume 5 is completing Lab 0, Lab 1, Lab 3, and the Capstone (approximately 30–45 hours). Completing all Labs in full takes roughly 60–85 hours.

Lab Dependencies

cpp
Lab 0 (joining_thread / thread_guard)

  ├─→ Lab 1 (BoundedBlockingQueue, ConcurrentCache)
  │     │
  │     ├─→ Lab 2 (SpscRingBuffer)        ─ 独立实现,不依赖 Lab 1
  │     │
  │     ├─→ Lab 2.5 (Debugging Lab)        ─ 复用 Lab 02 的代码作为诊断素材
  │     │
  │     └─→ Lab 3 (ThreadPool)             ─ 复用 Lab 1 的 BoundedBlockingQueue
  │           │
  │           ├─→ Lab 4 (Coroutine Scheduler) ─ 关闭语义参考 Lab 3
  │           │     │
  │           │     └─→ Lab 5 (Channel/Actor) ─ 可复用 Lab 1 的队列
  │           │
  │           └─→ Capstone (Mini Runtime)   ─ 组合 Lab 05 的组件

Environment Setup

All Labs share the following environment requirements:

  • Compiler: GCC 12+ or Clang 15+ (C++20 with full coroutine support)
  • CMake: 3.14+
  • Testing framework: Catch2 v3 (header-only, fetched via FetchContent)
  • TSan: compiler flag -fsanitize=thread -g
  • Platform: Linux or WSL2 (required for the epoll portion of Lab 4)
  • Valgrind (optional, required for helgrind in Lab 2.5)

Each Lab article begins with a specific CMakeLists.txt template that can be used directly.

v0.7.0-9-g940ec1b · 940ec1b · 2026-07-05