Coroutine Intuition in C++
summary
Coroutines in C++20 are functions that suspend and resume using stackless frames and promises; examples include a Fibonacci generator implemented as a lazy range, async IO awaitables that register OS callbacks, and task continuations that form linked-list continuations for composition. Resuming a live coroutine costs about a virtual call, while frame allocation can be expensive. Patterns include schedulers with batching and priority, thread-to-thread resumption, and massive concurrency; anti-patterns are simple dispatch loops and ad-hoc state-splitting. Libraries like cppcoro, asio and unifex provide usable implementations.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:05C++20 coroutines overview
- 7:49History of coroutines
- 13:26Stackful vs stackless
- 17:40Core components
- 24:22Generators
- 26:28Composition and continuations
- 29:35Async I/O
- 31:46Massive concurrency
- 35:00Scheduling techniques
- 38:05Execution environments
- 39:52Task graphs
- 43:02Pitfalls
- 50:50Summary
related talks
01h 27mManage Asynchronous Control Flow With C++ Coroutines
47mHow to start using coroutines
52mCoroutines: C++ vs Rust
01h 31mC++ Coroutines Demystified
01h 26mC++ Coroutines - Don’t Try This at Home
01h 14mHow to Use C++20 Coroutines for Networking
01h 05mCoroutines: C++ vs Rust
52mCoroutines are Qt: safer thread pools interactions
