_Project B Notes_ (Michael Safyan) *Milestones* 1. Non-preemptive * Create a thread * Yield * Exit 2. Same as #1, but adds priorities 3. Preemption, synchronization primitives. _*NOTE*_: Milestones can be implemented in any order, but will be more straightforward if done in order above. *Preemption * Generating the interrupt is easy; handling it /correctly/ is difficult. Interrupt may be interrupted. *B-Public.txt* * Skeleton of milestone #3. * Creates 8 worker threads ("thr_compute"). * Creates 1 monitoring thread ("thr_mon"). * tickSz=0 is a special case => non-preemptive. * "uthr_destroy" (destructor to "uthr_create" constructor) not in spec, but can be created/added as desired. *Ucontext-basic.txt* * Context created with "getcontext", "makecontext". * Swap between context with "swapcontext". * swapcontext(&from,&to) means: o Save current context into "from". o Jump to context stored in "to". * swapcontext is similar to "setjmp" followed by "longjmp", but uses "trampoline" (details: "/usr/include/ucontext.h"). *Context * Context contains: * Machine/hardware context (i.e. hardware registers) o Stack Pointer (SP) o Program Counter (PC) [Intel terminology: Instruction Pointer (IP)] o General purpose registers (e.g. "EAX", "EBX", "ECX", "EDX", etc. in x86; "r0", "r1", etc. RISC-like CPU) o ... * Software context (e.g. signal mask) *Addendum *Official documentation for "ucontext.h": http://www.opengroup.org/onlinepubs/009695399/basedefs/ucontext.h.html Functions "getcontext", "makecontext", and "swapcontext" are defined in the X/Open System Interfaces Extension (XSI).