Threads
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
- Threads may resume out of order
- Procedures are LIFO
- Thread can make many procedure calls
- More than one thread can run at a time
- Only one procedure runs at a time
Switching Threads
General (from kernel)
Hardware Interrupt (timer)
Sched_Scheduler()
- Determine which thread to run next
Sched_Switch()
- Switch the running thread