Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!brutus.cs.uiuc.edu!jarthur!elroy.jpl.nasa.gov!ames!amdcad!light!bvs From: bvs@light.uucp (Bakul Shah) Newsgroups: comp.lang.c Subject: Re: Can you help (was Jumping then jumping back again) Keywords: longjmp jump coroutine schedule thread Message-ID: <1990Feb10.090813.700@light.uucp> Date: 10 Feb 90 09:08:11 GMT References: <1797@neon.siesoft.co.uk> Reply-To: bvs@light.UUCP (Bakul Shah) Distribution: comp.lang.c Organization: Bit Blocks, Inc. Lines: 40 In article <1797@neon.siesoft.co.uk> huw@xstuart.siesoft.co.uk (Huw Roberts) writes: >I remember there was a discussion a little while ago on coroutines/ >lightweight processes and portable ways of implementing them in C. >I think the original subject was "Jumping then jumping back again". >I wonder if someone would be good enough to send me a summary of the >conclusions of the mail thread since I do not believe we have any way >of getting access to an archive of the discussion (we are not on >Internet and have no access to ftp or niftp). There were many such threads.... Here is one point of view based on implementing coroutines on two very different architectures. To implement coroutines what is needed is an ability to save and restore a coroutine's context (which consists of, usually, all of the registers minus the temps that get destroyed across a call). On many machines, but not all, this is effectively what the setjmp/logjmp routines do so on these machines you can implement coroutines entirely in C. On machines with setjmp/longjmp that are smarter and/or more picky you will need some assembly glue. Then there are machines with two stacks (register stack & memory stack) which add their own complication. Also note that N coroutines will *need* N stacks but C does not need more than one (assuming a new frame is not malloced on every call). A C machine with only one stack (and no way to switch it) can be strictly standard conforming and yet won't allow you any coroutines (you can emulate them but that is different). I think if you *want* portable coroutines in C, you have to add some standard extension to it. Something like old_stack = stack_switch(new_stack) will do. The point is, in order to manage processor registers properly the coroutine context switcher and the compiler have to collaborate. Also, the extended language would have to guarantee sane behavior when stacks are switched. -- Bakul Shah ..!{ames,sun,ucbvax,uunet}!amdcad!light!bvs