[Stackless] can it be done with setjmp/longjmp?

Russ Cox rsc at plan9.bell-labs.com
Wed Feb 27 03:37:07 CET 2002

> [proposal about using setjmp/longjmp and alloca as a 
> ``portable'' fall back for switching stacks]

This seems like a terrible idea.  Using alloca to put an entire
stack frame back doesn't even seem like it would work, and 
if it did would depend on the underlying compiler and
machine architecture.  At this point you might as well just
write the ten lines of assembly to do the stack switching.

>   > Just how portable is setjmp/longjmp these days? It's been quite a while
>   > since I looked at it.
> I have no idea. Articles say that set/longjmp is fair, with a few
> exceptions. I can give you a number of references.

If you mean how portable is a setjmp/longjmp implementation,
it's not.  It depends on the compiler and architecture, since
you're doing things behind the compiler's back.

If you mean how portable is a setjmp/longjmp-based coroutines
implementation (which seems like a more likely question), the answer
is fairly portable.  I've written and run coroutine packages based
on setjmp and longjmp on a number of systems.  As mentioned
in the pth paper, sometimes setjmp and longjmp are buggered and
don't allow use for coroutine-like applications, but writing your
own isn't hard.  It's between five and twenty lines of assembly
depending on the number of registers that need saving; you
write it once and don't worry about it after that.


Stackless mailing list
Stackless at www.tismer.com

More information about the Stackless mailing list