C++ Coroutines from scratch
summary
Starts from plain functions and implements working coroutines: a chat generator with promise methods yield_value/return_value and await_transform, an interleave generator turned into a proper range by adding a custom iterator, and a simple cooperative scheduler that stores void handles in a std::list and resumes tasks round robin. Code uses std::coroutine_handle and suspend_always/suspend_never, shows heap allocation of the coroutine frame, and demonstrates that generators, range-based for iteration and a scheduler all compile and run as expected.
AI-written summary · about
chapters (14)
- 0:00Introduction to C++ coroutines
- 2:39Functions vs coroutines control flow
- 6:11What are coroutines
- 11:33Coroutine elements in C++
- 15:45Code simplicity note
- 16:32First coroutine chat example
- 27:41Coroutine handle and promise type
- 34:22Tasks and generators defined
- 35:28Interleaving vectors with coroutines
- 43:45Range-based for loop support
- 47:18Scheduling multiple tasks
- 53:22Global scheduler and co_await
- 56:38Summary and next steps
- 58:12Q&A on stack and memory
related talks
01h 16mC++ Feature Coroutines, Beginner Friendly
01h 36mUnderstanding C++ Coroutines by Example, Part 2: Generators
01h 26mC++ Coroutines - Don’t Try This at Home
01h 01mUnderstanding C++ Coroutines by Example, Part 1
58m“Introduction to C++ Coroutines"
48m“Coroutines: what can't they do?”
01h 30mC++ Coroutines and Structured Concurrency in Practice
01h 23mImplementing a C++ Coroutine Task from Scratch
