Lecture 4
Context switches aren't required when switching between threads, only processes.
So when would it be better to have processes than threads?
- Answer: protection. Processes are protected from one another by the operating system, whereas threads are not. It is easier for threads to corrupt the stack or heap of another thread running within the same process.
Questions
Question 3
Question Three
A. True or False?
- Threads are faster to create and destroy than processes
- In a multi-threaded process the PCB is replaced by multiple TCBS
- Memory and other fields are not replicated in the TCB because the data is not needed by threads
B. (True or False?)
Using N threads within a single process is more efficient than using N separate processes because
a. The threads share the same code and data
b. Only the threads can take advantage of multiple CPUS
c. Only threads can block independently from one another
Answer: A
Question 4
Multiple threads within a process (3)
- Will always execute the same sequence of instructions
- Must execute within disjoint parts of the shared program
- may execute different sequences of instructions within any part of the shared program
Using N threads within a single process is more efficient than using M separate processes because (1)
- the threads share the same code and data
- only the threads can take advantage of multiple CPUs
- only threads can block independently from one another
Question 5
A. With a multi-threaded process, a context switch between threads is
performed by the OS kernel: (2)
- Only with user-level threads
- Only with kernel-level threads
- Always
- Never
Answer: 2:because the kernel isn't aware of user-level threads, only kernel-level threads.
B. With a multi-threaded process, each TCB maintains a separate copy of the
thread state (running, ready, or blocked) but the PCB must also have a copy of
the process state (running, ready, or blocked)
- Only with kernel-level threads
- Only with user-level threads
- Always
- Never
Answer: 2: because the kernel isn't aware of user-level threads, but it has to be aware of process status.
C. Kernel calls are (?) to manage threads
- needed only with kernel-level threads
- needed only with user-level threads
- always needed
- never needed
**Answer 1: **: needed only with kernel-level threads
Question 6
Do the following apply to Processes, Threads, or Both?
Can share virtual address space: Threads
Take longer to context switch: Processes
Have an execution context: Both
Make use of explicit communication mechanism: Both?
What is the difference between a process context switch and a thread context switch (within the same process)?
- Answer: a thread context switch will not cause a mode-switch to occur.