~/talk

Immediately Invoked Coroutine Lambdas in C++23 - Lifetime Pitfalls & Best Practices

Talkat ACCU 2025 · 2025-04-01..04-04· [c-and-cpp, compilers-and-language-design]
links:none on file
slides:none on file

Shows a crash scenario when an immediately invoked coroutine lambda captures an awaitable, moves only a pointer into the coroutine frame, and later resumes on another thread causing a dangling capture and undefined behavior in a thread pool queue flow. Demonstrates the concrete fix using C++23 this auto to pass captures by value so the coroutine frame owns them, and a macro-backed lambda invoker pattern that creates an inline coroutine scope; the examples compile and prevent the described lifetime bugs.

AI-written summary · about

  1. 0:00Introduction to Coroutine Lambdas
  2. 0:15Why Use Coroutines in C++
  3. 0:30The Problem with Awaitables and Handles
  4. 0:58Building an Immediately Invoked Coroutine Lambda
  5. 1:24Lifetime Issues and Crashes
  6. 2:01Compiler Lowering and Dangling Captures
  7. 2:46The Solution: Pass by Value with Deducing This
  8. 3:23Using 'this auto' in Lambdas
  9. 3:54Cleaner Syntax with Lambda Invoker and Macros
  10. 4:47Final Advice and Best Practices
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.