Mark Crispin <MRC(a)CAC.Washington.EDU> wrote:
Stacks are very useful, but they are not the solution
to everything.
Absolutely agreed.
One of the biggest deficiencies of C is its lack of
co-routines, since
it only has the stack style of subroutine calling. Yeah, I know about
setjmp/longjmp, but those are one-way, not true co-routines.
Well, setjmp and longjmp are pretty powerful. see
http://www.cs.uiowa.edu/~jones/opsys/threads/
for a machine-independent user-level thread package implemented in C using
setjmp and longjmp for control transfers between threads. It comes very
close to what a real coroutine afficianado would like. (Writing the
thread launch code in a machine independent way was murder.)
Curiously, the same thing can be done without longjmp()! I had a student
write me a thread package in Pascal once. All he needed was a mechanism
to convert pointers to integers and back again (easy enough in standard
Pascal, so long as it doesn't check variant records). Given this, his
code did essentially the same thing as my thread package.
Of course, talking about co-routines to youngsters is
likely to get
their eyes to glaze over, since they won't have a clue as to what I'm
talking about.
Indeed.
Doug Jones
jones(a)cs.uiowa.edu