I see they are excellent for concurrent programming but is it possible to utilise all cores of processor effectively with coroutines?
My tutorial and take on C++20 coroutines
61–70 of 144 posts
Re: My tutorial and take on C++20 coroutines
#62I see they are excellent for concurrent programming but is it possible to utilise all cores of processor effectively with coroutines?
You still need threads.
Re: My tutorial and take on C++20 coroutines
#63Earlier quoted context omitted.
> . And now we abolished this, ... no. coroutines are not supposed to be used in, like, more than an extremely small fraction of your codebase if you want to keep your code understandable
Eh, I think coroutines are a convenient way to achieve concurrency and parallelism. If you limit mutation and try to reduce the long reaching accessibility of variables then I think they’re generally very understandable, especially compared to other concurrency/parallelism paradigms.
but how often do you need concurrency and parallelism outside of handling network requests and performing some complicated math algorithm (which may be in a lib that you don't touch anyways, e.g. FFT>) ?
e.g. most UI code has to run on the main thread due to macOS / Windows limitations, and in most UI software it is extremely rare to have the kind of chains of callbacks whose readability gets improved by coroutines.
Re: My tutorial and take on C++20 coroutines
#64Is learning modern C++ worth the effort in 2021? I know classic c++, but don't really use it anymore.
> Is learning modern C++ worth the effort in 2021? (Hopping onto this topic,) I wonder, what are the right resources for properly diving into the modern C++? Are there books that are up to date? Tutorials? What has worked for HNs the best?
Re: My tutorial and take on C++20 coroutines
#65Earlier quoted context omitted.
I don't know how to answer that. For me, it is 100%, but it is a small sample size and one where I, in part, set the standard. If you have a C++11 code base, you don't really lose anything by adopting C++17, and you do gain a few things.
Interesting; I've always mistakenly assumed that C++ codebases working with different standards would necessarily end up being a patchwork.
Re: My tutorial and take on C++20 coroutines
#66Is learning modern C++ worth the effort in 2021? I know classic c++, but don't really use it anymore.
Re: My tutorial and take on C++20 coroutines
#67Some notes: - C++20 coroutines are stackless , meaning that multiple coroutines will share a single OS thread stack. This is non-obvious when you first look in to them them because coroutines look just like functions. The compiler does all the work of ensuring your local variables are captured and allocated as part of the coroutine yield context, but these yield contexts are not stack frames . Every coroutine you inv…
I'm trying to wrap my head around what the implication of stackless coroutines is. Can I use them like `yield` in Python+Twisted, i.e. to implement single-threaded, cooperative parallelism? It would not expect to be able to plainly call a function with a regular call, and have that function `yield` for me - but can I await a function, which awaits another, and so on? As far as I understand, C++20 coroutines are just…
There is a proposal for executors that would add event loops to C++. In the meantime boost.Asio (also available outside of boost) is one of the best options (the standard proposal was originally based on Asio, and Asio is tracking the standard proposal closely).
Re: My tutorial and take on C++20 coroutines
#68Earlier quoted context omitted.
Interesting; I've always mistakenly assumed that C++ codebases working with different standards would necessarily end up being a patchwork.
I'm sure someone will come up with a counterexample, but my experience is that pretty much everything is backwards compatible.
Re: My tutorial and take on C++20 coroutines
#69Is learning modern C++ worth the effort in 2021? I know classic c++, but don't really use it anymore.
As much as I like some replacement candidates, C++ is everywhere, so if you want to do anything related with graphics, machine learning, compiler development, OS drivers ,IoT toolchains, and not having the burden to sort out infrastructure problems by yourself, then C++ is the less painful way to go. Some would say C, but in domains like machine learning, you really don't want to write plain old C for what is running…
Still, with all its issues, I do quite like the language, but unless you want to work on some industry that is C++-centric, I do not think it is worth learning just for the sake of it.
Re: My tutorial and take on C++20 coroutines
#70Earlier quoted context omitted.
Your analysis of history there is a bit lacking. Coroutines didn't go out of fashion because of OOP, it went out of fashion because of structured programming and higher level languages. Coroutines are doable if you're programming directly in assembly, but if you want to do it in C-like structured languages, it turns out that it's really tricky: the whole concept of those languages are about having a single stack and…
> Basically the only languages with full stackful coroutine support in wide use are Lua and (sort-of) Go. Aren't Javascript Generators also coroutines?