- Lab 5: Portable Multithreading
Paper: Portable Multithreading The Signal Stack Trick For User-Space Thread Creation
Given job.c, write a program to have output:
- $ job0 has finished stage1
- $ job1 has finished stage1
- $ job2 has finished stage1
- $ job0 has finished stage2
- $ job1 has finished stage2
- $ job2 has finished stage2
- Programming language view: thread -- control flow (process -- program)
- System view: thread -- machine state: some in memory, some in registers
- How to manipulate machine state: ucontext
- See Section 2.3 for implementation
- But it's not portable enough. Any portable functions that save and restore machine contexts?
- int setjmp(jmp_buf env);
- void longjmp(jmp_buf env, int val);
- See Section 3 for implementation.
- We are not allowed to set up the value of stack and program counter in jmp_buf manually. What is a portable way to manipulate stack?
- int sigaltstack(const stack_t *ss, stack_t *oss);
Author: Zhuoqun (Tom) Cheng.