News for hackers. Stuff that matters.
Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by girvo on Sunday May 06, 2018 @10:59PM (#17010092)
What’s a good example implementation of stackful coroutines?
Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by ioquatix on Sunday May 06, 2018 @11:24PM (#17010197)
There are two kinds of stackful coroutines - fibers and green threads.

The difference is that fibers stay on the thread they were created on, while green threads can transit between OS threads. There have also been projects to cooperatively schedule OS level threads to minimise latency, but that's a bit different.

I don't know that many decent green thread implementations [off the top of my head], but an interesting one is yahns: https://yhbt.net/yahns/design_notes.txt - to me, green threads have all the benefits of coroutines but all of the downsides of multi-threaded programming.

I implemented fiber based concurrency for C++ here: https://github.com/kurocha/async. An example would be https://github.com/kurocha/async-network/blob/d1d2bf12eb2d9b... - calling read yields the fiber if it would block as implemented here: https://github.com/kurocha/async/blob/2edef4d6990259cc60cc30...

I implemented almost exactly the same model for Ruby here: https://github.com/socketry/async and if you are interested in how it works, see these projects which build on it: https://github.com/socketry/async#see-also

Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by RussianCow on Sunday May 06, 2018 @11:00PM (#17010097)
Any sort of "green thread" implementation, such as Python's greenlets.
Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by Tarean on Monday May 07, 2018 @12:26PM (#17014033)
Haskell does async IO by default using green threads. GHC allocates Thread State Objects which completely represent a (green) thread on the heap.

A capabillity which represents a cpu core contains a queue of TSO's. If a thread blocks on something it can also move to a different queue which is used for thread synchronization, blocking on computations from other threads, io etc.

Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by anonacct37 on Sunday May 06, 2018 @11:19PM (#17010177)
Would golang count?
Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by ioquatix on Sunday May 06, 2018 @11:51PM (#17010290)
Yes go would fit into the green thread bucket pretty well.
Re:The Various Kinds of IO – Blocking, Non-Blocking, Multipl... by ufo on Sunday May 06, 2018 @11:05PM (#17010117)
Lua coroutines work like this.