1 / 6

Context and Thread

Context and Thread. Chien -Chung Shen CIS, UD cshen@cis.udel.edu. Context. context type ucontext_t is defined in ucontext.h system header file typedef struct ucontext { struct ucontext * uc_link ; // resumed context sigset_t uc_sigmask ; // blocked signals

bena
Download Presentation

Context and Thread

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Context and Thread Chien-Chung Shen CIS, UD cshen@cis.udel.edu

  2. Context • context type ucontext_tis defined in ucontext.h system header file typedefstructucontext { structucontext *uc_link; // resumed context sigset_tuc_sigmask; // blocked signals stack_tuc_stack; // stack mcontext_tuc_mcontext; // CPU registers } ucontext_t; • uc_mcontext stores execution state (CPU registers and flags, program counter, stack pointer) • uc_link determines the context to be resumed when this context returns • $ man ucontext

  3. Get & Set Context • getcontext(ucontext_t *ucp)saves current context into ucp • setcontext(constucontext_t *ucp)restores context from ucp • successful call to setcontext()shall not return • program execution resumes at the point specified by ucp(transfer control to context in ucp) • $man getcontext • programloop.c

  4. Make Context • makecontext(ucontext_t *ucp, void (*func)(), intargc, ...) • modifiesthe context specified by ucp, which has been initialized by getcontext() • when this context is resumed using swapcontext() or setcontext(),program execution continues by calling func, passing it the arguments that follow argcin the makecontext()call • before calling makecontext(), the context being modified should have a stack allocated • uc_link determines the context resumed when the context being modified by makecontext()returns • $ man makecontextand program ctx.c

  5. Set Context • setcontext(constucontext_t *ucp)restores context pointed at by ucp • ucpshould have been obtained by a call of (1) getcontext()or (2) makecontext() • (1) program execution continues as if this getcontext()just returned • (2) program execution continues by a call to function funcspecified as the 2nd argument of that call to makecontext(); when funcreturns, we continue with the uc_link member of ucp specified as the 1st argument of that call to makecontext(); when this uc_link member is NULL, the thread exits

  6. Swap Context • swapcontext(ucontext_t *restrict oucp, constucontext_t *restrict ucp)saves current context in oucpand set (restore/resume) context in ucp • When successful, swapcontext()does not return

More Related