Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!ukc!axion!tigger!raph From: raph@tigger.planet.bt.co.uk (Raphael Mankin) Newsgroups: comp.lang.c Subject: Re^2: Coroutines in C Message-ID: <555@tigger.planet.bt.co.uk> Date: 12 Sep 89 11:12:38 GMT References: <214@castle.ed.ac.uk> <5899@ficc.uu.net> <10861@smoke.BRL.MIL> <5914@ficc.uu.net> Organization: RT5111, BTRL, Martlesham Heath, England Lines: 20 peter@ficc.uu.net (Peter da Silva) writes: >In article <10861@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >> In article <5899@ficc.uu.net> peter@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 . 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@planet.bt.co.uk