Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: Coroutines in C Message-ID: <5899@ficc.uu.net> Date: 28 Aug 89 13:09:08 GMT References: <214@castle.ed.ac.uk> Organization: Xenix Support, FICC Lines: 34 In article <214@castle.ed.ac.uk>, sam@lfcs.ed.ac.uk (S. Manoharan) writes: > In article <5773@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: > >In many C compilers I wouldn't even need to write any assembly code, since > >setjmp/longjmp can be used to implement the context switch. [ problem deleted to save space ] > Intutively, it appears the co-routines could be applied in this > context. Am I correct? I believe so. > And then, is there an easy way to tackle this problem? Have a look at my article a couple of weeks back where I introduced this subject, then implement coroutines :->. In existing, portable, C... no. > Since there could be a number of event?()s, I think setjmp() > and longjmp() would be of no help. The naive implementation of setjmp() is to save all the registers in jmp_buf. The corresponding naive implementation of longjmp is to restore those registers and return. If this implementation 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. This is, of course, hideously non-portable. But if the calling sequence for coroutines can be standardized then this non-portable code could be hidden inside co_call() and friends. -- Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation. Biz: peter@ficc.uu.net, +1 713 274 5180. Fun: peter@sugar.hackercorp.com. `-_-' "Just once I'd like to meet an alien menace that isn't immune to bullets" 'U` -- The Brigadier, Dr Who.