4 ms·
I have long thought that a coroutine mechanism was one of the most unfortunate omissions from the ANSI Common Lisp standard. The Lisp Machines had a mechanism
by ScottBurson 10y ago
I have long thought that a coroutine mechanism was one of the most unfortunate omissions from the ANSI Common Lisp standard. The Lisp Machines had a mechanism called "stack groups" that supported efficient coroutines, but I guess it wasn't considered critical for Common Lisp to have such a thing. As you've noticed, though, adding coroutines in a way that's general, efficient, and portable is very hard.
- codr4life 10y agoIndeed, I have made the same experience the hard way by trying all other ways to get there. It's one of the few things that I can't seem to pull off without help from above in Lisp. I'll settle for faster conditions for iters, but oh how I would have loved to do green threads with the same ease.
- kazinator 10y agoCoroutines are a hack that is inferior to both real threads (OS supported, true concurrency) and delimited continuations (are functions that multiply instantiate, compose and recurse). Both of these mechanisms can easily simulate coroutines. Many Common Lisp implementations have threads so effectively, Common Lisp de facto supports coroutines.
- codr4life 10y agoI guess you could implement generators and cooperative scheduling (which are useful abstractions with their own strengths, not inferior alternatives to threads) using threads. I never tried myself, but it feels backwards to me; like using 'loop' to iterate a list.
- ScottBurson 10y ago> Coroutines are a hack that is inferior to [...] real threads I don't agree. Sometimes you don't want to pay the price of the OS context switch. Anyway, in the context of the ANSI spec, threads were out of scope, but they could have done coroutines anyway. > ... and delimited continuations But CL doesn't have these, even de facto. Yes, there's CL-Cont, but it's pretty slow.
- codr4life 10y agoI went ahead and brain dumped the most obvious multi-threaded solution I could come up with, to get some performance facts to go with all the rumors. It comes out roughly 5x slower than using conditions/restarts. Just in case someone was wondering where we are atm...