Live data from Hacker News

A Mental Model for C++ Coroutine

uvdn7.github.io

1–10 of 20 posts

Re: A Mental Model for C++ Coroutine

#3
Note that with std::execution, c++26 will have a default async runtime (similar to how C# has a default async runtime).

This means that c++26 is getting a default coroutine task type [1] AND a default executor [2]. You can even spawn the tasks like in Tokio/async Rust. [3]

I’m not totally sure if this is a GOOD idea to add to the c++ standard but oh well.

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p35...

[2] http://wg21.link/P2079R5

[3] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p31...

Re: A Mental Model for C++ Coroutine

#4
post #2

Interesting article, but you should use a spell checker. Typos are distracting.

I am not a native speaker and I joke about my typos and grammar mistakes being the evidence that none of my code or post is AI generated. Sorry about the typos. I just fixed all the ones I can find. Hope it's better now.

Re: A Mental Model for C++ Coroutine

#5
post #4
post #2

Interesting article, but you should use a spell checker. Typos are distracting.

I am not a native speaker and I joke about my typos and grammar mistakes being the evidence that none of my code or post is AI generated. Sorry about the typos. I just fixed all the ones I can find. Hope it's better now.

i appreciate that you don't use AI. I like real human stuff

Re: A Mental Model for C++ Coroutine

#6

Note that with std::execution, c++26 will have a default async runtime (similar to how C# has a default async runtime). This means that c++26 is getting a default coroutine task type [1] AND a default executor [2]. You can even spawn the tasks like in Tokio/async Rust. [3] I’m not totally sure if this is a GOOD idea to add to the c++ standard but oh well. [1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p…

> I’m not totally sure if this is a GOOD idea to add to the c++ standard

What are the downsides? Naively, it seems like a good idea to both provide a coroutine spec (for power users) and a default task type & default executor.

Re: A Mental Model for C++ Coroutine

#7
post #6

Note that with std::execution, c++26 will have a default async runtime (similar to how C# has a default async runtime). This means that c++26 is getting a default coroutine task type [1] AND a default executor [2]. You can even spawn the tasks like in Tokio/async Rust. [3] I’m not totally sure if this is a GOOD idea to add to the c++ standard but oh well. [1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p…

> I’m not totally sure if this is a GOOD idea to add to the c++ standard What are the downsides? Naively, it seems like a good idea to both provide a coroutine spec (for power users) and a default task type & default executor.

well, Rust didn't do the same thing for a reason. Rust lets you pick and choose what async runtime to use (even though everyone has decided to use Tokio anyways). This is good because it allows for alternative async runtimes like Embassy (https://embassy.dev/) and it also doesn't freeze the API into something that can't change. It could totally be possible that people find a new style of async that works better than std::execution.

Re: A Mental Model for C++ Coroutine

#8
post #6

Earlier quoted context omitted.

> I’m not totally sure if this is a GOOD idea to add to the c++ standard What are the downsides? Naively, it seems like a good idea to both provide a coroutine spec (for power users) and a default task type & default executor.

well, Rust didn't do the same thing for a reason. Rust lets you pick and choose what async runtime to use (even though everyone has decided to use Tokio anyways). This is good because it allows for alternative async runtimes like Embassy ( https://embassy.dev/ ) and it also doesn't freeze the API into something that can't change. It could totally be possible that people find a new style of async that works better tha…

I don't know how it works for C++ but you're not locked down to a single implementation with how C# does it. You can have it use different executors/schedulers, different task types, etc.

Re: A Mental Model for C++ Coroutine

#9
post #8

Earlier quoted context omitted.

well, Rust didn't do the same thing for a reason. Rust lets you pick and choose what async runtime to use (even though everyone has decided to use Tokio anyways). This is good because it allows for alternative async runtimes like Embassy ( https://embassy.dev/ ) and it also doesn't freeze the API into something that can't change. It could totally be possible that people find a new style of async that works better tha…

I don't know how it works for C++ but you're not locked down to a single implementation with how C# does it. You can have it use different executors/schedulers, different task types, etc.

You are also not locked down in C++. There are already a handful of coroutine and async runtime implementations out there.

Re: A Mental Model for C++ Coroutine

#10
I’m excited to actually getting around to trying coroutines - they should be a good replacement for simple state machines. Rather than an storing an object with a state enum, I can write simple declarative code.
Post reply on HN