Longjmping back, and back again; Coroutines in C
Michael Meissner
meissner at dg-rtp.dg.com
Wed Nov 29 07:09:01 AEST 1989
In article <28112 at amdcad.AMD.COM> tim at proton.amd.com (Tim Olson) writes:
| In article <457 at enea.se> jerker at 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.
Another machine is the Data General MV running either the propriatary
operating systems (AOS/VS and AOS/VS-II) or the native UNIX (DG/UX).
The machine has a hardware stack which grows upwards instead of
downwards. In addition to a hardware stack pointer and frame pointer,
it has a stack base and stack limit pointer. The high level languages
all use the stack base pointer as an index into a per-task storage
area. The size of per-task storage area varies depending on how many
different languages are used, and what revisions of the libraries are
used. If the program only has one main task (or thread in
Mach-speak), and doesn't call sbrk directly, malloc'ed memory is
retreived by decrementing the stack limit pointer.
--
Michael Meissner, Data General.
Until 12/15: meissner at dg-rtp.DG.COM
After 12/15: meissner at osf.org
More information about the Comp.lang.c
mailing list