TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24903 27
24 Hard Rules for Writing Correct Async C++ (lessons from a 50K LOC Seastar codebase)

I've been building a C++20 service on Seastar and catalogued every class of bug that burned me into a set of rules I check on every commit. Each one cost at least a day to diagnose.

A few examples:

Lambda coroutines in `.then()` are use-after-free (the coroutine frame outlives the lambda that created it)
Coroutine reference parameters dangle (caller's scope ends before the coroutine resumes)
`std::shared_ptr` destructs on the wrong shard in Seastar's shared-nothing model
Missing & in do_with lambdas gives you a copy that dies while the future is still running

Some are Seastar-specific, but most apply to any coroutine-based async C++. The post covers the anti-pattern, why it breaks, and the fix for each.

https://ranvier.systems/2026/03/29/24-hard-rules-for-writing-correct-async-cpp.html

Curious if others have hit similar issues or have rules I'm missing.

https://redd.it/1s85qf1
@r_cpp
Ranvier 24 Hard Rules for Writing Correct Async C++ Async C++ will let you write a use-after-free that only manifests under load, on the third Tuesday of the month, in a stack frame that has nothing to do with the bug. The compiler won’t warn you. Your tests will pass. Your sanitizers will shrug. And then…
More from @r_cpp
  1. Oct 6, 2026Tuning a Server for Benchmarking https://david.alvarezrosa.com/posts/tuning-a-server-for-b…
  2. Oct 6, 2026boost.org has been rebuilt: new profiles, badges, search, and library filtering The Boost…
  3. Oct 6, 2026When (Not) to Use alloca() https://voithos.io/articles/when-not-to-use-alloca/ https://red…
  4. Oct 6, 2026MSVC Build Tools Preview updates – September 2026 https://devblogs.microsoft.com/cppblog/m…
  5. Oct 6, 2026I built MrDocs, an open-source C++ reference doc generator on the Clang/LLVM AST. Looking…
  6. Oct 6, 2026WasmBolt — The LLVM Project in your browser https://anutosh21.github.io/WasmBolt/ https://…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →