Unlike stackful coroutines (like Go goroutines or Lua coroutines), C++20 coroutines are completely stackless.
When a function contains co_await or co_yield:
- The compiler transforms the local variables into a heap-allocated
coroutine frameobject. - Generates an internal state machine.
- The
promise_typecustomizes return values viaget_return_object(),initial_suspend(), andreturn_value(). - Calling
handle.resume()continues execution at the exact yield suspension point without allocating an OS thread stack.