Path: utzoo!attcan!uunet!aplcen!samsung!gem.mps.ohio-state.edu!apple!sun-barr!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: Longjmping back, and back again; Coroutines in C Message-ID: <10199@goofy.megatest.UUCP> Date: 22 Nov 89 00:03:04 GMT References: <457@enea.se> Organization: Megatest Corporation, San Jose, Ca Lines: 26 From article <457@enea.se>, by jerker@enea.se (Jerker W}gberg): > I am trying to implement coroutines using plain C. My > application is not time critical, so there is no need for speed, > being portable is far more important. It would be great if there > was a way to switch stacks of the processes using just C. True. But there ain't. Any way you go will require some machine-dependent code, even if it's all written in C. (I've got an all-C coroutine package that works on Sun3's, but I know it would fail on a Sun4.) > I have figured out a way to implement this that works fine on a PC > with MSC 5.1, but wreaks havoc when run on a SUN4. The idea is that > instead of actually switching stacks, I use the "real" stack but > swap it in and out of malloced memory. (That's spelled "mallocked".) Anyway, on a SUN4, not all of the stack is located in contiguous main memory. The stack is implemented partially in "register-windows". Read the SPARC Architecture Manual if that sounds interesting. It's probably not trivial to implement coroutines on a SPARC. Not having tried it, I don't know. (There is a move afoot to put one on my desk, but I have to clean the desk first, so that's a big hurdle.) I think there is some kind of coroutine package that comes with the machine. Check it out.