[E-Lang] Deadlock-free [was what is good about E?]

Dan Moniz dnm@pobox.com
Tue, 17 Jul 2001 19:45:22 -0400


>[adding Cc: Guido van Rossum <guido@digicool.com>. --Z]

Likewise.

[snip]

>  --- Why Multithreading Sucks, Using Mojo Nation As An Example

[snip]

I've omitted all of Bryce's actual content not because he doesn't 
make excellent points (which he does), but because I wanted to focus 
on the statement "Why Multithreading Sucks".

Recently, when talking to friends and colleagues about what 
constructs they use in their programs to achieve concurrency, the 
default answer seems to be threads, especially pthreads.

Comp Sci. students and Kunth fans can feel free to skip over the rest 
of this mail, since it's really just advocacy of coroutines, the 
underdog of concurrent control structures.

I've been advocating the use of coroutines in places where I find the 
total hassle to be absorbed when using threads (code complexity 
during programming, debugging nightmares, platform-dependent thread 
code issues, etc.) to be greater than the overall benefit of having a 
working multithreaded application (itself a difficult ideal to 
achieve for reasons noted previously) but when a control structure 
that makes the application concurrent is still needed.

Coroutines, like anything else, are not a panacea. I do find, 
however, that your average garden variety hacker who wants to create 
concurrent applications (mostly in the context of network enabled or 
distributed apps) isn't aware of anything _but_ threads. Coroutines 
have gotten a bit more press lately due to Stackless Python 
<http://www.stackless.com/>, but it's still a pretty niche audience. 
Many CS students will be familiar with the concepts of coroutines, 
but rarely use them in practice after getting out into the real world 
because threads have the overwhelming majority of mindshare, 
especially in commercial software development shops.

So, in as much as my motive is to inform, I'd like to have more 
people consider coroutines. I'm not sure if they make sense for E (I 
would initially tend to doubt it, since Java already provides 
threads, but seeing as how this discussion arose out of possible 
changes to Java thread support, I suppose it's germane), but they do 
make sense in many other places where threads just seem to be too 
much bother than their worth.

Some good explanations of coroutines on the web include:

Coroutines in C by Simon Tatham, 
<http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html>, an 
application of Knuth's theory resulting in a stack-based mimic in C 
(Knuth wrote coroutines in assembly, C makes Kunth's coroutines 
impractical due to it's structure) applied to a C code problem. In 
related C hackery, Tom Duff's discussion of his Duff's Device has 
some related coroutine hints 
<http://www.lysator.liu.se/c/duffs-device.html>

Stackless Python, <http://www.stackless.com/>, mentioned above, and 
one of my favorite things about Python these days. Also see Tim 
Peter's Coroutines in Python 
<http://www.stackless.com/coroutines.tim.peters.html> and the 
python-coro (python-coroutines) mailing list 
<http://www.nightmare.com/~rushing/copython/>.

For the esoteric programming language geek like myself who may be 
lurking on the list, I offer 
<http://troubadix.physik.tu-berlin.de/~petz0433/beta/ecorout.html>, 
an example of coroutines in BETA (a OO langauge from the creators of 
Simula).

I couldn't dig much up on Java, but I didn't look too hard. I found 
<http://www.cs.utah.edu/%7egback/process/>, but it seems to be Java 
1.0 specific and pretty old.

P.S.: I would mention Scheme, but I don't think I have to in this group. ;]


-- 
Dan Moniz <dnm@pobox.com> [http://www.pobox.com/~dnm/]