Coroutines: C++ vs Rust
summary
Compares concrete designs: C++ coroutines let a user-provided promise/awaitable resume from the bottom up, own the state machine (heap by default, optimized to stack), and implement continuations to transfer execution between threads; Rust makes coroutines into typed futures that must be pinned, uses a waker and executor that polls futures top down, and keeps state as a compile-time type. Demos include a guard patrol, timer and socket read, a segmentation-fault loop fixed with tail-call-style resumptions, and a working thread-pool scheduling example.
AI-written summary · about
chapters (13)
- 0:00Intro
- 0:54Motivation: Guard Patrol
- 2:09Guard Patrol: State machine
- 4:01Terminology
- 6:30Defining a coroutine
- 8:51Implementing task
- 12:01Guard Patrol: C++ coroutine
- 18:25Guard Patrol: Rust coroutine
- 28:19Execute continuation in promise
- 35:38Compiler transformation
- 36:47Using a timer
- 37:18Implementing a timer
- 43:13Rust: Sockets
related talks
01h 05mCoroutines: C++ vs Rust
58m“Introduction to C++ Coroutines"
45mCoroutines: Kotlin Versus
41mCoroutines explained by example
57mCoroutine Intuition in C++
52mCoroutines are Qt: safer thread pools interactions
48mStructured Concurrency: Writing Safer Concurrent Code with Coroutines...
48m“Coroutines: what can't they do?”
