Re^2: Coroutines in C

Raphael Mankin raph at tigger.planet.bt.co.uk
Tue Sep 12 21:12:38 AEST 1989


peter at ficc.uu.net (Peter da Silva) writes:

>In article <10861 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>> In article <5899 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>> >If [simple setjmp] is used, it should be possible to create
>> >a fake stack frame and register set in a jmp_buf and tranfer control to it
>> >using longjmp.

>> You need separate (non-overlapping) stacks, not just a stack frame.
>> Otherwise the coroutines will step on each other's <DELETED>.

Provided you setjmp/longjmp saves tnd restores he full stack pointer
(MSDOS users beware here) it is quite possible to write coroutines in C.
I have in fact written a full multi-tasking supervisor (coroutines
with frills) entirely in C. This runs under MSC and the only kludge is
two lines of assembly code to do the initial stack-frame setup for new
tasks.
-- 
Raphael Mankin
raph at planet.bt.co.uk



More information about the Comp.lang.c mailing list