Opentopia Directory Encyclopedia Tools

Setcontext

Encyclopedia : S : SE : SET : Setcontext


setcontext is one of a family of C library functions (the others being getcontext, makecontext and swapcontext) used for context control. setcontext et al allow the implementation in C of advanced control flow patterns such as iterators and coroutines.

setcontext et al can be viewed as a more advanced version of setjmp/longjmp; where the latter just allows a single non-local jump up the stack, setcontext allows the creation of multiple coöperative threads of control, each with their own stack.

Usage

The four function calls, along with the types ucontext_t and mcontext_t, are defined in <ucontext.h>.

The ucontext_t type stores execution state, including all registers and flags, the instruction pointer, and the stack pointer.

See below for an example of usage.

Specification

setcontext et al are described in the Single Unix Specification, version 2. Not all Unix-like operating systems have the functions, a fact which has possibly led to their being little-used.

Example

#include 
#include 
#include 

static void loop_iter (ucontext_t *my_ucp, ucontext_t *loop_ucp, int *yield_i) }

int main (void) }

return 0; }

See also

External links

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: