nw@palladium.UUCP (Neil Webber) (06/12/88)
In article <16126@brl-adm.ARPA> ted%nmsu.csnet@relay.cs.net writes: > >But isn't the following idiom for co-routines useful? > > [ sample coroutine implementation deleted ] > Not on a vax running 4.3BSD it isn't: Script started on Sun Jun 12 11:20:08 1988 % cc -o coroutines coroutines.c % ./coroutines a b c longjmp botch Illegal instruction (core dumped) % script done on Sun Jun 12 11:20:28 1988 This happens because, as Chris Torek points out: >longjmp is not suitable for coroutines because it is valid >for longjmp to attempt to unwind the stack in order to find >the corresponding setjmp, and it is therefore legal for >longjmp to abort if it is attempting to jump the `wrong way' >on the stack. I don't believe that there is a portable way to *implement* a coroutining library in C, short of first implementing a processor emulation and then writing code for that processor :-). Perhaps someone can prove otherwise. The coroutining code posted by ted%nmsu.csnet@relay.cs.net does work on our Sun 3, *with the Sun compiler*. It does not work with the Greenhills compiler unless you take care to throw all the right compiler switches (force frame pointers, no delayed stack adjustments). David DiGiacomo (david@sun.uucp) suggests that the C compiler recognize alloca() as a special case. This certainly appears to be the way of the, er, umm, future. After all, inlining those strcpy calls gets the Dhrystone numbers way up ;-} -- Neil Webber / Epoch Systems, Marlboro MA / (617) 481-3717 {harvard!cfisun, linus!alliant}!palladium!nw