Implementing a C++ Coroutine Task from Scratch
summary
Live codes a working C++20 coroutine-based Task: implements the required promise type methods (initial_suspend, final_suspend, get_return_object, unhandled_exception), builds a Task wrapper with start(), handles nested co_await by storing a continuation and using synchronous transfer (returning coroutine_handle), and mocks an IO context to show async read completions. Debugs crashes and a memory leak by using a unique_ptr with a custom deleter that destroys the coroutine frame. Compiles on mainstream compilers and the prototype largely works after fixes.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 0:10Coroutines
- 1:53Why Coroutines
- 4:35Key Coroutines
- 5:20Coroutine Expression
- 9:42Veda Tab
- 10:14Quarantine Frame
- 16:04Minimum 4 Functions
- 16:23Demo
- 17:04Hint
- 18:53Hello World
- 20:32Implementing a Task
- 50:49Evasion test
related talks
01h 01mUnderstanding C++ Coroutines by Example, Part 1
01h 27mManage Asynchronous Control Flow With C++ Coroutines
01h 31mC++ Coroutines Demystified
47mHow to start using coroutines
01h 06mC++ Coroutines from scratch
48m“Coroutines: what can't they do?”
01h 26mC++ Coroutines - Don’t Try This at Home
48mStructured Concurrency: Writing Safer Concurrent Code with Coroutines...
