8. Threads and Thread Implementations Flashcards
What makes up a thread?
Registers and a stack
What are problems with the CPU that the OS tries to correct?
There is only one CPU (or usually fewer than there are processes needing to be run) and it is way faster than the other parts of the system
What is batch scheduling?
Running jobs sequentially until completion
How does the operating system create the illusion of concurrency?
By rapidly switching the CPU between multiple running tasks
How does the OS ensure that it retains control over what threads are using the CPU?
By using a periodic timer to generate hardware interrupts
What is the cost of doing a context switch?
Context switches require executing many instructions and saving a lot of state (registers and thread stack). This takes time.
How does the cost of context switching affect the rate at which the hardware timer fires to allow the kernel to potentially switch between threads?
The rate of timer firing cannot be too high, otherwise the overhead from the context switches will start to dominate the CPU and drag the system performance down
How are registers shared between threads or processes?
They are not. Registers are private to an individual thread. [?]
How is the stack shared between threads or processes?
The stack is shared by all the threads of a process. [?] Process’s stack is not shared between processes.
How is the address space shared between threads or processes?
The address space is shared by all the threads of a process [?] A process’s address space is not shared with other processes.
How is the file descriptor table shared between threads or processes?
The file descriptor table is shared by all the threads of a process. The file descriptor table is copied over if fork is called on a process, but not shared directly with another process.
Why do we use threads and not just processes?
Threads can be a good way of thinking about applications that do multiple things “simultaneously”. Threads may help applications hide or parallelize delays caused by slow devices
Lay out an analogy for the difference between threads and a process.
Multiple threads within a single process are like multiple cooks trying to prepare the same meal together.
Each one is doing one thing. They are probably doing different things. They all share the same recipe (instructions) but may be looking at different parts of it. They have private state but can communicate with each other easily enough. They must coordinate with shared resources!
How does a web server use multithreading?
Web servers use a separate thread to handle each incoming request
How do web browsers use multithreading?
Web browsers use separate threads for each open tab.
When loading a page, separate threads are used to request and receive each unique part of the page