Hacker News new | past | comments | ask | show | jobs | submit login

Isn't this really well trodden ground? Coroutines were known by the 60s, according to Wikipedia, and I have a really hard time believing that just about everything worth saying about them hasn't been said. I feel a little bit of scholarship would help avoid creating problems that have already been solved.



This comment doesn't add anything to the discussion. You could say this about anything, like say parsing, which was also "known by the 60's".

It's a "middlebrow dismissal": http://www.byrnehobart.com/blog/why-are-middlebrow-dismissal...

It ignores the difference between theory and practice. Whether you do coroutines in C, Python, or another language matters. Language features interact, and those interactions affect how you write specific programs, so treating it abstractly has limits. Python actually has 2 completely different notion of coroutine, both of which were implemented after the 60's.

The ground isn't really well trodden, because most languages don't have coroutines. Probably 99% of programs don't use coroutines (nearly every program in C, C++, Java). Pre-emptive threads are more common.

You also didn't mention any literature which would have "said all the things".

That said, here is a good paper from 2004 from the authors of Lua: Revisiting Coroutines. Among other things, it points out that "coroutine" doesn't mean one thing.

https://scholar.google.com/scholar?cluster=14280883920152261...


It's hard to give constructive criticism of the article, beyond suggesting background reading, because it seems both ignorant of existing research and naive as to the issues that arise.

Here are some of the relevant ideas and papers:

- "A coroutine is like a control construct"---a coroutine is a control construct. There is no "like". But there is a fundamental difference from a goto because it captures execution state (the stack and so on, also known as the continuation) which a goto does not. A continuation can only jump to program states that make sense (for some definition of "sense"---you can at least count on variables being initialised, for example). A goto can jump anywhere.

- "But coroutine is also like a variable"---a coroutine closes over an environment. I.e. it is a closure. This doesn't really have much to do with being "like a variable". Representing closures is well studied in programming language research and there are many techniques for handling it E.g. http://matt.might.net/articles/closure-conversion/

- "A coroutine can't be orphaned"---those are your continuations. You now need to worry about either heap allocating continuations or copying the stack. E.g. http://lampwww.epfl.ch/teaching/archive/advanced_compiler/20... And when do you free continuations? You probably need to GC them, as your control flow is now more complicated.

- "A coroutine can be orphaned"---this is where you need to think about semantics. What does it mean for a coroutine to be abruptly exited? It probably means leaking resources and hard to track down bugs. A lot of thought needs to go into this. (Somewhat relevant is this paper: https://www.cs.indiana.edu/~dyb/pubs/LaSC-7-1-pp83-110.pdf)

The rest of the article isn't so interesting to me, because I don't think thread cancellation should be possible at arbitrary times.

So that's some of the existing work in the field, but the biggest issue is the need to think about the semantics, or programming model, of the concurrent tools you're introducing. The article does very little of this. Can you actually understand programs written using some proposed concurrency primitives? That's where it really gets interesting, and where recent work like http://www.csc.kth.se/~phaller/doc/haller16-scala.pdf is making some thought provoking contributions.


>- "A coroutine is like a control construct"---a coroutine is a control construct. There is no "like".

Pedantic. A coroutine is a control construct in the same way an Exception is a control construct, or in the way a tomato or a cucumber is a fruit.

Adopting a particular naming depends on the categorization and the intention, not merely on the capabilities of a construct.

Even more so in a post, were the notion needs to be introduced to people who only associate the concept of a "control construct" to the more explicit and tamer constructs referred to as such, if and for loops, goto, etc.

>- "But coroutine is also like a variable"---a coroutine closes over an environment. I.e. it is a closure. This doesn't really have much to do with being "like a variable". Representing closures is well studied in programming language research and there are many techniques for handling it E.g. http://matt.might.net/articles/closure-conversion/*

The first part is just a formal definition, which doesn't negate the statement, and the latter part is just a generic reference to research on closures.

One could use the same kind of saying-nothing responses to all kinds of posts or papers.


"One could use the same kind of saying-nothing responses to all kinds of posts or papers."

You misunderstand.

If you know the name of the concept you can search for more information.

If you read the section on "But a coroutine is also like a variable" you'll see the author is struggling with how to represent coroutines. Closure conversion deals with representation.


Given the recent discussions around co-routines in Rust, even if everything has been said, there's still a wealth of stuff in this space, and figuring out what makes sense for a given language is a lot of work, regardless if it's been in some paper somewhere already or not.


I agree. The interaction of features within a particular language requires a lot of thought. However this particular article (at least how I read it) was talking in generalities, and wasn't tied to a particular language.


In my experience, there's an academic world, and a practical world, and never the 'twain shall meet.

The academic world knew without experience that higher-level structured concurrency was the way to go. It took the practical industry decades of unmaintanable pthread messes to learn the same lesson, but they ultimately learned it.


Any interesting links to academic research of higher-level structured concurrency?


Here's one interesting paper: http://www.csc.kth.se/~phaller/doc/haller16-scala.pdf

Here's the general algorithm:

1. Find something interesting

2. Chase the references and read them.

3. Chase the citations (use Google Scholar) and read them, if they're relevant.

You'll pretty soon have an understanding of the general approaches and issues.

(If you throw "coroutine concurrency" into Google Scholar you'll very quickly find citations from the 80s discussing this model.)


You forgot the step where you beg, borrow and steal to get around the journal paywalls.


Most researchers in programming languages publish their papers on their home pages. In CS Ed I'm discovering it's very different.


Sci-hub makes it too easy now!


>I feel a little bit of scholarship would help avoid creating problems that have already been solved.

Anything particular, besides a vast generalization?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: