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
One-to-one model
OS sees / understands threads, synchronization
Must go to OS for all operations
Negative: portability
Many-to-one model
Totally portable
Negative: OS has no insight into app needs
OS may block entire process if one user-level thread blocks
Many-to-many model
Can have bound or unbound threads
Negative: requires coordination between user-level and kernel-level thread managers
Types of thread scope
System and Process
System Scope
system-wide thread management by OS-level thread managers
Process Scope
user-level library manages threads within a single process
Multi-threading Patterns
Boss/Workers
Pipeline
Layered
Boss/Workers
Boss assigns work
Workers perform work (limited by boss performance)
throughput = 1 / boos_time_per_order
Pipeline
Entire task == pipeline of threads
Throughput == weakest link
Shared-buffer based comm. b/w stages
Layer Pattern
each layer group of related tasks
Not suitable for all applications
Synchronization