Generators are dead, long live coroutines, generators are back | Inside Rust Blog
(blog.rust-lang.org)
from runiq@feddit.de to rust@programming.dev on 24 Oct 2023 09:02
https://feddit.de/post/4881447
from runiq@feddit.de to rust@programming.dev on 24 Oct 2023 09:02
https://feddit.de/post/4881447
What is this title
threaded - newest
The only language to get it right was Simula 67.
Could you explain to me how simula’s implementation of coroutines differ from modern languages (be it stackless or stackful)? I tried to dig a little but didn’t find much and I don’t really have time to investigate further.
Thank you!
Guys and girls, This problem has been solved in 1980 already. Why are we still struggling?
It’s called Communicational Sequential Routines. Like, why do we have to come to full circles and Rust after a decade still hasn’t solved the “Async”/Multithreading problem. It’s mind boggling to me, Im sorry, people are gonna hate me for me being frustrated, but I just can’t say that it’s irritating that Rust, a language that really has offered many great ideas, STILL hasn’t figured out how to properly do things like channels and sequential communication? A concept that has been invented since the 80’s? Or if that doesn’t fit at least see how it could fit Rust’s standards?
It’s HORRIBLE that Rust as a language and community STILL uses Tokio and Async-Std and we can’t even decide always which one of the two to use and while they also have some incompatibilities afaik, and this is just for ASYNC. Multithreading and Async? God bless your soul if you’re going to do that in Rust, because prepare for debugging for days and for many weird issues and caveats.
Go, a much MORE inferior in features language has done it. What makes it so difficult to inherent such or a similar approach? It’s a simple concept. Channels. In and out. And syntax and scheduler like Goroutines to make it easy to have async AND multithreading without the caveats Rust has nowadays if you were going to do such thing.
www.usingcsp.com/cspbook.pdf
.
The section titled “what is the difference” doesn’t explain what the difference is, only what a generator is (which I already knew).
It’s essentially a name change.
The two concepts are very similar, with the main difference being coroutines can receive arguments after invocation and generators generally cannot (here’s a good explanation if you want to get more into it). Here’s a write up about Rust’s implementation, they’re more than generators and from reading over it they may allow passing data in with each resume (I haven’t played with them in Rust, but I’ve used the concept a lot in Lua, Python, and Go).
Then again, like the second link says, the boundaries of both can vary conversation to conversation. Python generators, for example, can also be used as coroutines (see this PEP).
Simulation 67 keeps the coroutine data on the heap (it is garbage collected).