When longjmp() is called, all of these registers are restored automatically, and execution continues when setjmp() called, but this time setjmp() has a different return value (similar to how fork() has different return values ββin the parent and child) .
setjmp() / longjmp() save only a limited environment. In particular, they just keep the stack pointer, not the full stack, so you can return only to the same function or to the calling function. POSIX has setcontext() , which allows you to switch between stacks, which makes it more useful for implementing things like user-environment threads (fibrils, green threads, ...).
source share