Title: 544
Tags: lec11

Q: There is one virtual address space per _______
A: process

Q: A process is a running ______
A: program

Q: Virtual memory maps to ______
A: physical memory

Q: Which address space can contain "holes" (invalid addresses)
A: Virtual address spaces can have holes (physical address spaces do not -- they are contiguous)

Q: What are three things that go in a virtual address space?
A: code
stack
heap

Q: Which pointer indicates what code to execute next?
A: The "instruction pointer"

Q: There is one stack per _____ and one heap per ______
A: thread, process

Q: What is it called when the scheduler stops running one thread and starts running a different one?
A: A "context switch"

Q: What are three states a thread can be in?
A: running, blocked, ready

Q: What are some reasons a thread might be blocked?
A: waiting on user input, disk operations, network operations, timer sleep, etc.

Q: How do you create and launch a thread object for running function f(x)?
A: t = threading.Thread()
t.start(target=f, args=[x])

Q: How do you wait for a thread t to finish running?
A: t.join()

Q: How can you print a thread's ID?
A: t.get_native_id()

Q: What is a "race condition"
A: A bug that only sometimes surfaces, depending on when context switches happened between threads

Q: When might a context switch occur?
A: Between instructions -- a single line of code might correspond to multiple bytecodes or machine instructions, so it's important to note that context switches often occur in the middle of a line of code being executed.