5 ms·
There were three competing coroutines designs in front of the standard committee: stackful coroutines, from boost; C#-like stackless coroutines from MS; and zer
by gpderetta 5y ago
There were three competing coroutines designs in front of the standard committee: stackful coroutines, from boost; C#-like stackless coroutines from MS; and zero-overhead stackless coroutines initially from chriskohlhoff (but then picked up by many others).
After a lot of back and forward, the committee decided to pick the most proposal (i.e. the MS one) with the most complete implementation and potentially less ambitious. These are both good good features, but we ended up with a very complex, hard to use, design that requires unspecified compiler magic to remove all overhead.
Interestingly enough the committee went in the opposite direction for networking recently rejection the battle tested ASIO, again from chriskohlhoff, for a yet unproven design initially from Facebook, now Nvidia.
edit: personally I'm a huge fan of stackfull coroutines, but I could have lived with zero overhead stackless coroutines. The current design is IMHO the worst solution. Then again, sometimes it is better to ship something than argue forever.
- otabdeveloper4 5y agoASIO is a horrible godawful mess, in this I agree with them.
- gpderetta 5y agoI doubt you will like S/R then.
- inetknght 5y agoI disagree. ASIO has been (mostly) intuitive for me to use. The hardest part is that it doesn't have great documentation and that it sometimes changes paradigms (eg, the recent change in executors has been super annoying and lead to problems in migrations). But of course it really depends on how you think when you write software. If you don't really think asynchronously then you're going to have trouble.
- gpderetta 5y agoAny supposedly high performance async abstraction is almost necessarily going to be complex and flexible otherwise people will keep using the low level system API.
- R0b0t1 5y agoI can't agree with this. If you deviate from the ASIO examples even a little bit it blows up in your face spectacularly, and I sunk a lot of time into reading the implementation to see how it works. They should have stayed away from ASIO. It looked like they were going to, for a while, and it looked like it was going to be better than boost's implementation. But here I find out that was never the case and the portions that needed filled in required compiler support.
- R0b0t1 5y agoTo clarify -- there's some stub of new boost ASIO kicking around that's good, or the unfinished C standard stuff looks ok. But straight ASIO is pretty bad.
- Longhanks 5y agoEric Niebler recently switched from Facebook to NVIDIA. I wonder if that has anything to do with it.
- gpderetta 5y agoYes of course, he is the main author of the S/R proposal. Edit: btw, I'm a huge fan of Eric work and he was my GsoC mentor back in '06. It is just sad that we got into an either-or situation and we couldn't get Net TS in the standard.
- nickelpro 5y agoSince when is the Net TS dead?
- nrclark 5y agoThey talked about it in the latest cppcast episode. It's not dead officially yet, but it's dead.
- tomcam 5y agoWould you mind giving me the TLDR on no overhead? Seems impossible to me
- gpderetta 5y agoWhat it seems impossible? You can easily implement 0-overhead coroutines yourself with macros and the duff device. They are just cumbersome. Chris proposal was "just" syntactic sugar over that. He went so far as producing a working implementation on a clang branch. The most important difference to what was eventually standardized is that the coroutine object is a non type erased value type (basically very similar to a lambda, and in fact an extension on top of it). The big issue is that it was very hard to use safely as the address of local variables could potentially change between invocations if the coroutine is copied around.
- ot 5y agoI've been on the fence for a while about coroutines, but I have to say that libraries like folly coro do a very good job at hiding all the complexity (the library itself though is somewhat impenetrable). Facebook is very invested in coroutines, all major internal libraries at this point have a coroutine interface (in particular Thrift auto-generates coro client interfaces), and they have enjoyed wide adoption, way beyond the small cabal of C++ gurus. Personally what sold me is cancellation handling. It really is magical. Are your concerns about frame allocation? Is this something that the nanosecond-latency crowd particularly cares about? :)
- gpderetta 5y agoFor networking allocating the frame is perfectly reasonable because you need to allocate some sort of control structure anyway and you can do it off a custom allocator. In fact i think that stackful coroutines are probably a better fit. My issue is stackless coroutines would be perfect for generators but the required allocation kind of kills it :(.
- ot 5y ago> In fact i think that stackful coroutines are probably a better fit. My experience with fibers is that they're stack overflow generators. Presumably you want lots of them running concurrently, so you'll need a small stack size, and now you have to be extremely careful about what code you run in them as it's very easy to run out of stack. You can't rely on overcommit because if you actually end up touching the pages you're stuck with them. > My issue is stackless coroutines would be perfect for generators but the required allocation kind of kills it :(. That's true, though it depends on the granularity of the operations you want to run in your generators. Ranges+algorithms should cover most of the simple/small cases?
- new_realist 5y agoIn my experience, you overcommit virtual address space and have the compiler generate max stack size information. You then work to remove giant allocations. Not ideal, but the price for bespoke speed and debuggability.