Ai Os CH4
Ai Os CH4
Operating Systems
Ch4: Threads
1. Benefits
3. Types of Parallelism
4. Multithreading Models
5. Implicit Threading
6. Thread Cancellation
2
Threads
3
Single-Threaded versus Multi-Threaded
4
Benefits
5
Benefits of Multithreaded Programs
6
Multi-core Programming
Challenges
7
Multi-core Programming Challenges
• Identifying tasks. divide program into tasks that can run in parallel.
• Balance. Ensure that these tasks perform equal work of equal value.
• Data splitting. Divide data between tasks that run on separate cores.
9
Data Parallelism
10
Task Parallelism
11
Multithreading Models
Many-to-one model Many-to-many model
One-to-one model Two-level model
12
User Threads versus Kernel Threads
• Support for threads may be provided either
• At the user level, for user threads.
• By the operating system, for kernel threads.
14
One-to-One Model
15
Many-to-Many Model
16
Advantages of Many-to-Many Model
17
Two-Level Model
18
Implicit Threading
19
Explicit Threading
20
Implicit Threading
21
Thread Pool
23
Thread Cancellation
24
Thread Cancellation
• Refers to terminating a thread before it has completed.
• Cancellation of a target thread can be asynchronous or deferred.
• Asynchronous cancellation
• One thread immediately terminates the target thread.
• Deferred cancellation
• The target thread periodically checks whether it should terminate.
• This allows the target thread to terminate itself in an orderly fashion.
25
Thank You
26