P2L2 Flashcards
Benefits of Multithreading
Parallelization
Specialization
Efficiency
Context switch formula
if (t_idle) > (2*(t_ctx_switch))
Multi-threaded OS Kernel has..
- threads working on behalf of apps
- OS-level services like daemons or drivers
what the OS needs to support Threads
Thread data structure
mechanisms to create and manage threads
mechanisms to safely coordinate among threads
Synchronization Mechanisms
- Mutual exclusion
- Waiting on other threads
- Waking up other threads from wait state
Bizzell Thread Type
thread ID, Program Counter (PC), Stack Pointer (SP), registers, stacik, attributes
Mutex
a lock
Critical Section
code blocked by mutex
Signal
notify one thread waiting on condition
Broadcast
notify all threads waiting on condition
spurious wake-ups
when threads are woken up when they may not be able to proceed
Deadlock
two or more competing threads are waiting on each other to complete, but none of them ever do
Options to prevent deadlock
Deadlock prevention (EXPENSIVE) Deadlock detection and recovery (ROLLBACK) Ostrich Algorithm (DO NOTHING)
Kernel vs User level thread
User-level thread must be associated with kernel level thread, then OS scheduler must schedule kernel-level thread
Multithreading Models
One-to-one
Many-to-one
Many-to-many