DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getcontext(S-osr5)


getcontext, setcontext -- get and set current user context

Syntax

cc . . . -lc
#include <ucontext.h>

int getcontext(ucontext_t *ucp);

int setcontext(ucontext_t *ucp);

Description

These functions are useful for implementing user level context switching between multiple threads of control within a process.

getcontext initializes the structure pointed to by ucp to the current user context of the calling thread. The user context is defined by ucontext(FP) and includes the contents of the calling thread's machine registers, signal mask and execution stack.

setcontext restores the user context pointed to by ucp. A successful call to setcontext does not return; program execution resumes at the point specified by the context structure passed to setcontext. The context structure should have been one created either by a prior call to getcontext or makecontext or passed as the third argument to a signal handler (see sigaction(S-osr5)). If the context structure was one created with getcontext, program execution continues as if the corresponding call of getcontext had just returned. If the context structure was one created with makecontext, program execution continues with the function specified to makecontext.

Return values

On success, setcontext does not return and getcontext returns 0. On failure, setcontext and getcontext return -1 and set errno to identify the error.

Diagnostics


[EFAULT]
The pointer ucp did not print to a valid address.

Limitations

When a signal handler is executed, the current user context is saved and a new context is created by the kernel. If the thread leaves the signal handler via longjmp (see setjmp(S-osr5)) the original context will not be restored, and future calls to getcontext will not be reliable. Signal handlers should use siglongjmp (see setjmp(S-osr5)) or setcontext instead.

Files


/lib/libc.a
linking library

See also

makecontext(S-osr5), setjmp(S-osr5), sigaction(S-osr5), sigaltstack(S-osr5), sigprocmask(S-osr5), ucontext(FP)

Standards conformance

getcontext and setcontext are conformant with:

AT&T SVID Issue 3.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005