I think coroutine/goroutine is very useful in case of a lot of concurrent small tasks must be performed quickly. Current std::thread
cannot meet the requirements, because of its heavy cost.
I also think coroutine/goroutine cannot be supported simply through a C++ library, it should be implemented directly by the language's core features. Because coroutine/goroutine has a special semantics, which doesn't have a corresponding concept in current C++ standard.
Provided that we add a new keyword cppgo
, then we may write code as follows:
void f(int n)
{
...
}
int main()
{
for (int i = 0; i < 10000; ++i)
{
cppgo f(i);
}
}
How cool it would be!
Has the C++1y standard considered to support coroutine/goroutine?
There are several proposals related to coroutines but they don't target C++14 but a later version. Here are a few of these proposals:
resumable
functions and await
instruction/expression(?))There are other more or less related papers (look at concurrency related papers and future related papers and you'll see a tendency toward allowing coroutines).
Some people also discuss the possibility to have a general syntax for "unwrapping monads" (like the await
keyword proposed in 1 ) which would work both for std::future
and other non-concurrency related types like optional
or expected
. Such features would allow to seamlessly apply the same algorithms to both resumable and not resumable functions, with or without concurrency being involved. In theory at least.
Here is a list of discussions related to these coroutine and monad concepts, by people doing and criticizing these proposals:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With