Lecture: threads & switching
Preparation
- read OSPP ยง4, Concurrency and Threads
Processes and threads
- locks recap
- mutual exclusion
- boils down to
xchg
on x86
- safety? progress? fairness?
- performance? scalability?
- problem: # 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
- review CSE 333 on processes/threads
A thread implementation
- virtual CPU state
- registers
- SP: point to a separate stack
- PC: where to resume execution
- how/where are other registers saved
- scheduling state: running, runnable, killed, etc.
- cooperative scheduling: threads give up control by calling yield
- useful?
- downsides? how would you improve it?
- uthread implementation
- scheduler activations