The No-Return / Multiple-Return Approach

In this approach, we create two special functions for context switching. One function has the special property that it never returns, but restores a prior context. As a compliment, the other function has the special property that it can return multiple times by first saving the current context (see figure below) (C already provides a primitive form of these functions with the longjmp and setjmp commands respectively, which are tailored to the compiler just to save the current ``C'' state.) These functions provide a great flexibility at the cost of complexity. The notion of a function that never returns or a function which returns multiple times is a little strange and unconventional. And it is easy to ``screw up'' by doing such things as longjmping into an unsaved or expired context, or mixing up the different returns from setjmp. Some higher-level approach may be more appropriate...

Figure: Control Flow of the Two Approaches to Context Switching
\begin{figure}
\begin{verbatim}
No-Return / Multiple-Return Switch Funct...
...vert \vert * \vert \vert
V V * V V
x 1 * y 1
*\end{verbatim}
\end{figure}