Path: utzoo!attcan!uunet!mcsun!ukc!edcastle!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.lang.c Subject: Re: Longjmping back, and back again; Coroutines in C Message-ID: <1384@skye.ed.ac.uk> Date: 21 Nov 89 17:42:00 GMT References: <457@enea.se> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 33 In article <457@enea.se> jerker@helios.se (Jerker W}gberg) writes: >I am trying to implement coroutines using plain C. Tricky! >instead of actually switching stacks, I use the "real" stack but >swap it in and out of malloced memory. Aaargh! What a hack! >1. Can somebody explain why this fails on a SUN4. Sun 4s have "register windows" which means that the variables that would be near the top of the stack are instead in registers. As a quick hack with a remote chance of working, you could try burying your stack copying code at the bottom of about 20 trivial procedures, so that the relevant register windows will have been flushed. This is just a guess, and may well not work. >3. Does anyone know of a better way to do coroutines in C ? Sun OS 4 has a library for coroutines (which they refer to as threads). One of my more inventive friends produced some code for coroutines that worked under Berkeley-like Unixes; it worked by using sigstack(), signal() and kill() to start executing on a malloc()ed stack. -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin