Path: utzoo!attcan!uunet!lll-winken!sun-barr!newstop!sun!amdcad!proton!tim From: tim@proton.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Longjmping back, and back again; Coroutines in C Message-ID: <28112@amdcad.AMD.COM> Date: 21 Nov 89 15:01:52 GMT References: <457@enea.se> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Austin, Texas Lines: 25 Summary: Expires: Sender: Followup-To: In article <457@enea.se> jerker@helios.se (Jerker W}gberg) writes: | | 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. Sorry, but there just isn't a way that is portable to all architectures; there is almost always some assembly-language involved. | 2. Are there more machines out there that probably will throw up | when executing this code, apart from CPU's where the stack is | growing upward instead of downward. This can be taken care of, | but I did not want to clutter the example below. Here's an example of one: The Am29000 (32-bit RISC processor) uses a large number of registers as a "stack cache", and spills and fills these to/from an area in memory when it overflows. Another (separate) memory stack holds non-scalar data, such as arrays and large structures. Your routine would only attempt to swap the memory stack, leaving the register stack cache alone. -- Tim Olson Advanced Micro Devices (tim@amd.com)