Lecture 12: Processes and threads
Preparation
Processes and threads
- # of tasks > # of CPUs
- programming abstraction: virtual CPUs
- process API: fork/execve/exit/kill/wait/getpid
- thread API: pthread etc.
- definitions I
- process: address space, hosting one or more threads
- thread: basic execution and scheduling unit
- definitions II
- threads and processes are both tasks
- threads: tasks with shared address space
- example: Linux
clone
syscall
- questions
- T/F - writing to memory location x in process A
will change the value at the same memory location x in process B
- T/F - thread A creates a file descriptor; thread B can access it
A thread implementation
- virtual CPU state
- registers
- SP: implies a separate stack
- IP: for resume
- scheduling state: running, runnable, killed, etc.
- exercise
- new:
git clone -b uthread https://github.com/xiw/xv6.git
- if you have cloned xv6:
git pull; git checkout -b uthread
- uthread.c
- uthread_switch.S
- cooperative scheduling: threads give up control by calling yield
- useful?
- downsides? how would you improve it?