Skip to main content

Section 4.1 Concurrency and Threads

This section covers book chapter 26. Start with the introduction and section 26.1, about what threads are.

Practice 4.1.1.

Which of the following must be switched out when a context switch happens between threads within the same process?
  • The values in the registers
  • The program counter
  • The stack pointer
  • The page table information
  • The TLB cache information

Practice 4.1.2.

Which of these are reasons to use multiple threads, instead of multiple processes?
  • We want to share date between the threads.
  • We want to run things on multiple CPUs.
  • We want to do something else while waiting for I/O.
Read section 26.2 for an example of thread creation.

Practice 4.1.3.

Practice 4.1.4.

Figures 26.3, 26.4, and 26.5 show three possible "thread traces" of how the execution of the same lines of code could happen. Come up with at least four more possible scenarios.
Read sections 26.3 and 26.4, discussing the problem involving shared data.

Practice 4.1.5.

    True or False: A race condition occurs when multiple threads are about to perform changes to the same data, and the order in which these steps are done may change the outcome.
  • True.

  • False.

Practice 4.1.6.

    True or False: A critical section is a piece of code that accesses a shared variable that should not be concurrently executed by more than one thread. Doing so can lead to race conditions.
  • True.

  • False.

Read section 26.5 about the meaning of "atomic operations", and synchronization primitives.
Read section 26.6, about the problem of waiting for another part of the system, and 26.7 about a summary.
You have attempted of activities on this page.