Understanding C++ Coroutines by Example, Part 1
summary
Builds a minimal coroutine library from the ground up: a task + promise type, the five mandatory promise functions, get_return_object, initial/final_suspend behavior, and how co_await is lowered to awaitable checks and suspend/resume. Implements a task::operator co_await, a final awaitable that resumes a continuation, and a sync_wait using std::promise/std::future with atomic states to make it thread safe (atomic states: started/attached/finished). Demonstrates an async file read with worker thread, shows why detach can lose results, and recommends Lewis Baker’s cppcoro.
AI-written summary · about
chapters (14)
- 0:00Start
- 8:44Curtain Statement
- 11:16Initial Suspend
- 12:30Default Constructor
- 12:45Promise Pointer
- 14:40Get Return Objects
- 16:59Return Value
- 18:03Unhandled Exception
- 20:15Mandatory Member Functions
- 23:58Recap
- 27:16Operator Function Call
- 36:00Catch Clause
- 42:40Suspend
- 55:11Implementation
related talks
01h 23mImplementing a C++ Coroutine Task from Scratch
01h 16mC++ Feature Coroutines, Beginner Friendly
58m“Introduction to C++ Coroutines"
48m“Coroutines: what can't they do?”
01h 06mC++ Coroutines from scratch
01h 26mC++ Coroutines - Don’t Try This at Home
48mStructured Concurrency: Writing Safer Concurrent Code with Coroutines...
56mWhat we've been (a)waiting for?
