Professional Documents
Culture Documents
Multi Threading
Multi Threading
Chapter 4: Threads
Overview
Multithreading Models
Threading Issues
4.2
Objectives
To introduce the notion of a thread a fundamental unit of CPU utilization that forms the basis of
multithreaded computer systems
4.3
threads overview
A thread is a basic unit of CPU utilization; it comprises a thread ID, a
It shares with other threads belonging to the same process its code
task at a time.
4.4
4.5
Motivation
A web browser might have one thread display images or text while another thread retrieves data from the network.
Ex. A word processor may have a thread for displaying graphics, another thread for responding to keystrokes from
the user, and a third thread for performing spelling and grammar checking in the background.
4.6
Benefits
Responsiveness
Resource Sharing
Economy
Scalability
4.7
Multicore Programming
Dividing activities
Balance
Data splitting
Data dependency
4.8
4.9
Concurrent Execution on a
Single-core System
4.10
Parallel Execution on a
Multicore System
4.11
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
4.12
Many-to-One
Examples:
4.13
Many-to-One Model
4.14
One-to-One
Examples
Windows NT/XP/2000
Linux
4.15
One-to-one Model
4.16
Many-to-Many Model
4.17
Many-to-Many Model
4.18
Two-level Model
Similar to M:M, except that it allows a user thread to be bound to kernel thread
Examples
IRIX
HP-UX
Tru64 UNIX
4.19
Two-level Model
4.20
Thread Libraries
Thread library provides programmer with API for creating and managing threads
4.21
Threading Issues
Asynchronous or deferred
Signal handling
4.22
Thread pools
Thread-specific data
Scheduler activations
4.23
4.24
Thread Cancellation
Deferred cancellation allows the target thread to periodically check if it should be cancelled.
4.25
Signal Handling
Signals are used in UNIX systems to notify a process that a particular event has occurred.
1.
2.
3.
Signal is handled
Options:
4.26
Thread Pools
Advantages:
Usually slightly faster to service a request with an existing thread than create a new thread
Allows the number of threads in the application(s) to be bound to the size of the pool
4.27
Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
4.28
Scheduler Activations
Both M:M and Two-level models require communication to maintain the appropriate number of kernel
threads allocated to the application
Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread
library
This communication allows an application to maintain the correct number kernel threads
4.29
Lightweight Processes
4.30
End of Chapter 4