classsc_cor_pkg {
public:
...
virtual sc_cor* create(size_t stack_size,sc_cor_fn* fn, void* arg );
virtualvoidyield( sc_cor* next_cor ); // yield to function assoc. with next_corvirtualvoidabort( sc_cor* next_cor ); // quit and transfer control to next_cor
...
};
sc_cor abstract class
wait: suspend a thread -- internally calls sc_cor_pkg::yield
typedefstructucontext {
// context which will be resumed when current context terminates.// in case the current context was created using makecontext structucontext*uc_link;
sigset_tuc_sigmask; // in <signal.h>stack_tuc_stack; // in <signal.h>// machine-specific representation of saved context, including calling// thread's machine registersmcontext_tuc_mcontext;
...
} ucontext_t;
getcontext(ucontext_t *ucp)
save current context into "ucp"
setcontext(ucontext_t *ucp)
restores the user context pointed at by ucp
successful call does not return (just jump!)
ucp should have been obtained by
getcontext() or
makecontext() or
passed as third argument to a signal handler
makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
initial setup:
getcontext(ucp): saves current context into ucp
allocate a stack space in ucp->uc_stack
define successor context and assign it to ucp->uc_link
makecontext(ucp, foo, args):
later:
setcontext(ucp) is called or swapcontext() is called
foo(args) is called
when foo(args) returns, successor context (uc_link) is activated