Lecture 4


Context switches aren't required when switching between threads, only processes.

So when would it be better to have processes than threads?

Questions


Question 3

Question Three

A. True or False?

  1. Threads are faster to create and destroy than processes
    • True
  2. In a multi-threaded process the PCB is replaced by multiple TCBS
    • False
  3. Memory and other fields are not replicated in the TCB because the data is not needed by threads
    • True

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)

  1. Will always execute the same sequence of instructions
  2. Must execute within disjoint parts of the shared program
  3. 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)

  1. the threads share the same code and data
  2. only the threads can take advantage of multiple CPUs
  3. 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)

  1. Only with user-level threads
  2. Only with kernel-level threads
  3. Always
  4. 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)

  1. Only with kernel-level threads
  2. Only with user-level threads
  3. Always
  4. 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

  1. needed only with kernel-level threads
  2. needed only with user-level threads
  3. always needed
  4. never needed

**Answer 1: **: needed only with kernel-level threads

Question 6

Do the following apply to Processes, Threads, or Both?

  1. Can share virtual address space: Threads

  2. Take longer to context switch: Processes

  3. Have an execution context: Both

  4. Make use of explicit communication mechanism: Both?

  5. What is the difference between a process context switch and a thread context switch (within the same process)?