Threads

Pasted image 20231207145558.png

Thread is a sequence of instructions

What are threads?

Schedulable execution context

  • something that could execute on a core but also includes its the global context

Used to run multiple tasks that a process is responsible for at the same time

Implementation of Thread

Why use threads?

  • Lighter weight than processes
  • Allows processes to use multiple processors or cores in parallel
  • Allows a single program to overlap its I/O and computation

Typically at least one Kernel Thread for every process

Threads vs. Procedures

Switching Threads

General (from kernel)

Pasted image 20231207185732.png

Hardware Interrupt (timer)

Pasted image 20231207185802.png

Sched_Scheduler()

Sched_Switch()

Trapframe vs Switchframe