4 ms·
Structured Concurrency
- jiehong 6y agoThe title could just be “coroutines in C++, because of callback hell”. Feels like C++ is catching up…
- secondcoming 6y agoBoost has had coroutines for years. But then you have to use Boost...
- yxhuvud 6y agoHaving access to coroutines and having a predefined lifetime for them is quite different.
- toolslive 6y ago> by making async lifetimes correspond to ordinary C++ lexical scopes ... That's the easy part and typically not entirely what you want. Suppose you have some fibers you launched via a parmap. Most of these will end more or less at the same time, but some will be laggards and these need to be tracked in some way. That tracking typically happens outside of your current lexical scope as they might not influence the success of the composed fiber.
- Joker_vD 6y agoNurseries and cancellation support, as in [0]? [0] https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ https://vorpus.org/blog/notes-on-structured-concurrency-or-g...
- The_rationalist 6y agoSo which language have a great structured concurrency implementation? I can only think of C++20 and of Kotlin
- toolslive 6y agoOcaml's Lwt lets you set this up quite easily.
- mping 6y agoJava's upcoming project loom supports structured concurrency [1]. I gave it a shot and it works great. [1] https://wiki.openjdk.java.net/display/loom/Structured+Concurrency https://wiki.openjdk.java.net/display/loom/Structured+Concur...
- MisterTea 6y agoOld concept but Plan 9 c and thread(2) is simple yet really nice to work with. Also helps that there is no posix junk and plan 9 threads are light weight processes with shared memory. So libthread lets you spawn and manage processes or threads and groups them in rendezvous groups to guarantee sequential thread execution. That can eliminate the need for locks since no two threads in a rendez group will be running at the same time. Then use channels to read/write messages between procs. Way better pattern than async/await nonsense. http://man.postnix.pw/9front/2/thread http://man.postnix.pw/9front/2/thread example code (random 9 mirror I picked): https://github.com/mischief/9problems/blob/master/sys/src/libthread/example.c https://github.com/mischief/9problems/blob/master/sys/src/li...
- valenterry 6y agoHaskell and Scala are top notch in this area. Probably one of their biggest advantages. I always feel a bit sad when I see that other programming languages try to solve the same problem and come up with an inferior solution that they then try improve by fixing edge cases. I wish programming language authors would learn more from each other.
- Jtsummers 6y agoAda's tasks are interesting from this perspective. There's more on it here (I had trouble finding good online tutorials/examples, this one is part of a larger set of Ada learning materials): https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Developer/chapters/11_Concurrency.html https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Devel...
- secondcoming 6y agoDo coroutines help with the need for sharing state with timers? When you make a async operation there are two things: the operation itself, e.g. read/write and the timer associated with that operation (you really don't want infinite timeouts in production code). Both need information about the async operation in their respective handlers. You can't do composed operations (std::move(this)) since one of the read/write or timer handlers will be given a moved-from object. The only wasy I can see to solve this is through the use of a ringbuffer and using indexes into this ringbuffer as a 'handle' to the async op (see LMAX's Disruptor). It saves from needing shared_ptr / enable_shared_from_this. You're going to need a bounded queue anyway to prevent a fast producer from causing OOM.
- dreamcompiler 6y agoI'm not a C++ programmer but there are a lot of words like "continuations" and "coroutines" being thrown around here to describe things that look to me like simple lexical closures. Am I wrong?