Lab: Multithreading

Uthread: switching between threads (moderate)

This task is very similar to scheduling different processes in xv6 kernel:

  1. User thread yield the CPU ↔ One process yield CPU in its kernel thread: yield()
  2. User threads and xv6 processes all have to store their own running context: proc->context, cpu->context
  3. Switching threads and processes both require storing and loading registers: kernel/swtch.S

Note:

Using threads (moderate)

We have to add locks to preserve concurrent reading and writing to a simple hash table.

Barrier (moderate)

A point in an application at which all participating threads must wait until all other participating threads reach that point too. Here are my thoughts:

  1. bstate.round represents which barrier the farthest thread is on or will be on. Besides, every thread will know the number of its own current barrier.
  2. bstate.nthread represents the number threads blocked on the bstate.round, not the number threads being blocked.