The Lambda Coroutine Fiasco
https://github.com/scylladb/seastar/blob/master/doc/lambda-coroutine-fiasco.mdIt's amazing C++23's "deducing this" could solve the lambda coroutine issue, and eliminate the previous C++ voodoo.
44
Upvotes
View all comments
Show parent comment
2
u/foonathan Dec 19 '25
No, capturing by value does not ensure captures are copied into the coroutine frame! That is the entire problem.
The issue is that while the lambda object stores a capture by value, the
operator()still accepts*thisby reference, so only the reference to the lambda is captured into the coroutine frame, but not the lambda itself.(The context is something like
spawn([x] -> Task { ... }), i.e. the lambda is a coroutine itself. Then the arguments are copied intoTask's coroutine frame, but the arguments are athispointer to the temporary object in the stack frame that callsspawn.)