Chapter 5: Threads Overview Multithreading Models(多线程模型) Threading Issues Pthreads Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads 1 7/17/2018
Thread A thread, sometimes called a lightweight process(LWP), is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set , and a stack. A traditional (or heavyweight) process has a single thread of control or multiple threads of control. 2 7/17/2018
Single and Multithreaded Processes 3 7/17/2018
Benefits Responsiveness (相应度高) Resource Sharing Economy Utilization of MP Architectures (多处理器体系结构的利用) 4 7/17/2018
User Threads Thread management done by user-level threads library Examples - POSIX Pthreads - Mach C-threads - Solaris threads 5 7/17/2018
Kernel Threads Supported by the Kernel Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux 6 7/17/2018
Multithreading Models Many-to-One One-to-One Many-to-Many 7 7/17/2018
Many-to-One Many user-level threads mapped to single kernel thread. The entire process will block if a thread makes a blocking system call. Multiple threads are unble to run in parallel on multiprocessors. 8 7/17/2018
Many-to-One Model 9 7/17/2018
One-to-One Each user-level thread maps to kernel thread. Most implementations of this model restrict the number of threads supported by the system. Examples - Windows 95/98/NT/2000 - OS/2 10 7/17/2018
One-to-one Model 11 7/17/2018
Many-to-Many Model Allows many user level threads to be mapped to many kernel threads. Allows the operating system to create a sufficient number of kernel threads. Solaris 2 Windows NT/2000 with the ThreadFiber package 12 7/17/2018
Many-to-Many Model 13 7/17/2018
5 Threading Issues Semantics of fork() and exec() system calls. Thread cancellation. Signal handling Thread specific data 14 7/17/2018
Pthreads a POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. API specifies behavior of the thread library, not an implementation. Implementation is up to development of the library. Common in UNIX operating systems. 15 7/17/2018
Solaris 2 Threads 16 7/17/2018
Solaris Process 17 7/17/2018
Windows 2000 Threads Implements the one-to-one mapping. Each thread contains - a thread id - register set - separate user and kernel stacks - private data storage area 18 7/17/2018
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 of the parent task (process) 19 7/17/2018
Java Threads Java threads may be created by: Extending Thread class Implementing the Runnable interface Java threads are managed by the JVM. 20 7/17/2018
Java Thread States 21 7/17/2018
Summary Overview Multithreading Models(多线程模型) Threading Issues Five threads Pthreads Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads 22 7/17/2018