Coroutines for Dummies
summary
C++20 coroutines make async code readable but hinge on how co_await transforms an expression into an awaitable with await_ready/await_suspend/await_resume; the compiler saves locals into a coroutine frame and gives an opaque coroutine_handle (a glorified callback). Examples include an awaitable adapter around a callback-based load_from_store, a my_sleep that first spawns threads then a scheduler-backed version, both working but revealing that suspend_never vs suspend_always control eager vs lazy behavior and that final_suspend=suspend_always can keep frames (leaks) while promise allocation is implicit.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:48What is a coroutine
- 5:20C++20 coroutine keywords
- 10:54Coroutine handles explained
- 13:02First awaitable type
- 26:09Return object and promise type
- 33:25Basic coroutine demo
- 38:19Is this a coroutine?
- 40:26Threads and suspension demo
- 51:05Final suspend behavior
- 55:55Ordering and threads
- 1:00:42Suspend always impact
- 1:03:27Coroutines vs async
- 1:07:19Scheduler and multiple coroutines
- 1:15:27Summary
related talks
48m“Coroutines: what can't they do?”
58m“C++ Coroutines - a negative overhead abstraction"
57mC++ Coroutines: Under the covers
01h 01mWhat We’ve Been Awaiting For? - How to Build a C++ Coroutine Type
56mGenerators, Coroutines and Other Brain Unrolling Sweetness
01h 05mImplementing async with coroutines and fibers - project Loom in C#
43mHow coroutines are designed
31mGenerators, Coroutines and Other Brain Unrolling Sweetness
