Академический Документы
Профессиональный Документы
Культура Документы
Chapter 4: Threads
Overview
Multithreading Models
Threading Issues
Pthreads
Windows XP Threads
Linux Threads
Java Threads
4.2
4.3
Benefits
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
4.4
User Threads
Thread management done by user-level threads library
Three primary thread libraries:
POSIX Pthreads
Win32 threads
Java threads
4.5
Kernel Threads
Supported by the Kernel
Examples
Windows XP/2000
Solaris
Linux
Tru64 UNIX
Mac OS X
4.6
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
4.7
Many-to-One
Many user-level threads mapped to single kernel thread
Examples:
4.8
Many-to-One Model
4.9
One-to-One
Each user-level thread maps to kernel thread
Examples
Windows NT/XP/2000
Linux
4.10
One-to-one Model
4.11
Many-to-Many Model
Allows many user level threads to be mapped to many kernel
threads
kernel threads
4.12
Many-to-Many Model
4.13
Two-level Model
Similar to M:M, except that it allows a user thread to be
Examples
IRIX
HP-UX
Tru64 UNIX
4.14
Two-level Model
4.15
Threading Issues
Semantics of fork() and exec() system calls
Thread cancellation
Signal handling
Thread pools
Thread specific data
Scheduler activations
4.16
4.17
Thread Cancellation
Terminating a thread before it has finished
Two general approaches:
4.18
Signal Handling
1.
2.
3.
Signal is handled
Options:
4.19
Thread Pools
Create a number of threads in a pool where they await work
Advantages:
4.20
4.21
Scheduler Activations
Both M:M and Two-level models require communication to
4.22
Pthreads
A POSIX standard (IEEE 1003.1c) API for thread
Mac OS X)
4.23
Windows XP Threads
Implements the one-to-one mapping
Each thread contains
A thread id
Register set
The register set, stacks, and private storage area are known
4.24
Linux Threads
Linux refers to them as tasks rather than threads
Thread creation is done through clone() system call
clone() allows a child task to share the address space
4.25
Java Threads
Java threads are managed by the JVM
Java threads may be created by:
4.26
4.27
End of Chapter 4