threads without kernel mods

Chris Torek torek at elf.ee.lbl.gov
Tue May 28 10:57:59 AEST 1991


In article <4815 at skye.ed.ac.uk> richard at aiai.UUCP (Richard Tobin) writes:
>... Once you have n stacks, you may be able to longjmp() between them.

And then again, you may not....  Longjmp is only defined for going `up'
the stack, and can (and does) abort programs that attempt to use it in
the `wrong' direction.  When you have two separate stacks and attempt
to jump from one to the other, you are going neither up nor down, but
the `<' comparison done internally gives an answer anyway (which answer
it gives depends on the relative addresses of the two separate stacks)
and thus implementations that check (such as 4.xBSD-on-a-VAX) may stop
your code dead, rather than changing stacks.

It is not impossible to implement this, but it *is* heavily machine
dependent.  Chances are you will get the best results not by trying
longjmp(), but rather by reading up on the machine's calling
conventions, the O/S's user stack conventions, and the machine
architecture, and writing the context switch code only once you
understand all of these.  It is probably best to continue to avoid
setjmp/longjmp as their specifications have changed in the past,
suggesting that they may change again in the future.  (Richard Tobin, I
note, used _longjmp.  This is what used to be called longjmp.  POSIX
now has sigsetjmp, apparently.  In other words, this is dangerous
territory.  You should know exactly what you are doing, or you will
step on a land mine.)
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek at ee.lbl.gov



More information about the Comp.unix.internals mailing list