Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!ukc!stc!datlog!tpm From: tpm@datlog.co.uk ( Tim Murnaghan ) Newsgroups: comp.unix.wizards Subject: Re: A very interesting problem -- multiprocessing Message-ID: <690@dlvax1.datlog.co.uk> Date: Wed, 6-May-87 12:17:27 EDT Article-I.D.: dlvax1.690 Posted: Wed May 6 12:17:27 1987 Date-Received: Sat, 9-May-87 09:43:15 EDT References: <7176@brl-adm.ARPA> <4589@sci.UUCP> <2017@utah-gr.UUCP> Reply-To: tpm@datlog.co.uk ( Tim Murnaghan ) Organization: Data Logic Ltd, Queens House, Greenhill Way, Harrow, London. Lines: 26 In article <2017@utah-gr.UUCP> thomas%spline.UUCP@utah-gr.UUCP (Spencer W. Thomas) writes: > > >Anyway, if you want to coroutine a couple of functions with no >arguments (easiest case), you just allocate a "large enough" chunk of >memory for each one's stack, set the stack pointer to the correct end >of it (top on a Vax), and call the function. (Oh, I should mention >that you need to save the real stack pointer somewhere.) The >"Suspend" action then saves the co-routine stack pointer in a static >variable, and resumes execution on the real stack. To continue a >co-routine, you restore its saved stack pointer and do a subroutine >return. Maybe a little code fragment would help: >.... Of course you don't have to use assembler to do the stack setting, setjmp remembers everything that you need. All you have to do is gallop down the stack until you've left enough stack for the coroutine below and then do your setjmp (we have a routine called gobble). Some implementors have qualms about longjmp'ing the wrong way which is a shame, but at least the asssembler bits can be hidden behind a standard interface when you write your own. We do actually use this sort of thing (with a bit more business for synchronisation ) keeping our co-routines on a list and having a noddy scheduler kick them off and calling them activities (for we are using the MOD methodology MASCOT).