计算机操作系统原理5
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Operating System Concepts
5.8
wency@cuit.edu.cn 2010
5.2 Multithreading Models (2)
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. Kernel threads can run in parallel on a multiprocessors If a thread performs a blocking system call, kernel can schedule another thread for execution. Overcomes shortcomings of many-to-one and oneto-one models. Examples -- Solaris 2, HP-UX, and Tru64 UNIX.
Operating System Concepts
5.6
wency@cuit.edu.cn 2010
5.2 Multithreading Models
Many-to-One
Many user-level threads
maps to single kernel thread. Entire process will block if a thread makes a blocking system call Only one can access the kernel at a time, so threads don’t run in parallel on multi-CPUs machine. Used on systems that do not support kernel threads.
Chapter 5: Threads
Overview Multithreading Models Threading Issues* Pthreads*
Solaris 2 Threads *
Windows 2000 Threads * Linux Threads * Java Threads *
programs
Semantics of fork() and exec() system calls. Thread cancellation. Signal handling Thread pools Thread specific data
Operating System Concepts
Operating System Concepts 5.2 wency@cuit.edu.cn 2010
Single and Multithreaded Processes
Operating System Concepts
5.3
wency@cuit.edu.cn 2010
5.1 Overview (1) -- Motivation
Operating System Concepts 5.4 wency@cuit.edu.cn 2010
5.1 Overview (2) -- Benefits
– Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, so increasing responsiveness. Resource Sharing – threads share memory and the resources of the process to which they belong. Code sharing allows an application to have several different thread of activity all within the same address space. Economy – allocating memory and resources for process creation is costly. Threads share resources of the process. It is more economical to create and context switch threads than process. Utilization of MP Architectures – in a MP architecture, each thread of multithreading can run in parallel on a different processor. It increases concurrency.
Examples-- POSIX Pthreads, Mach C-threads, Solaris threads
Kernel threads – supported directly by operating system.
Kernel performs thread creation, scheduling, and management in
Operating System Concepts
5.1
wency@cuit.edu.cn 2010
5.1 Overview
Thread – sometimes called lightweight process
(LWP), is a basic unit of CPU utilization;
Traditional process – or heavyweight process;
has a single thread of control. A process having multiple threads of control can do more than one task wenku.baidu.comt a time.
Operating System Concepts
library and with no support from the kernel.
threads creation and scheduling are done in user space without
intervention of kernel, so they are fast to create and manage.
requests. When receiving a request, it creates a process to service that request. A more efficient way is to have one process that contains multiple threads to serve the same purpose.
Such as web browser, web server, word processor.
Solutions for a single application (such as web
server) to perform several similar tasks:
Have server run as a single process to accept
Operating System Concepts
5.9
wency@cuit.edu.cn 2010
Many-to-Many Model
Operating System Concepts
5.10
wency@cuit.edu.cn 2010
5.3 Threading Issues
Several issues to consider with multithreaded
thread, may burden performance of an application. Require to restrict the number of threads supported by system. Examples -- Windows 95/98/NT/2000, OS/2
Responsiveness
Operating System Concepts 5.5 wency@cuit.edu.cn 2010
– User and kernel Threads
User thread – management done by user-level threads
5.1 Overview (3)
Comprises a thread ID, a program counter, a register
set, and a stack. Shares with other threads belonging to the same process its code section, data section, and other OS resources, such as open files and signals.
5.11
wency@cuit.edu.cn 2010
5.4 Pthreads
a POSIX standard (IEEE 1003.1c) API for thread
creation and synchronization. API specifies behavior of the thread library, implementation is up to development of the library. Common in UNIX operating systems.
kernel space. If a thread performs blocking system call, the kernel can schedule another thread in the application for execution. In multiprocessor environment, kernel can schedule threads on different processors. Examples-- Windows 95/98/NT/2000, Solaris, Tru64 UNIX, Linux
Operating System Concepts 5.7 wency@cuit.edu.cn 2010
5.2 Multithreading Models (1)
One-to-One -- Each user-level thread maps to a kernel thread.
allowing another thread to run when a thread makes blocking. Allows multiple threads to run in parallel on multiprocessors But each user thread needs creating a corresponding kernel
Many software packages running on modern
desktop PCs are multithreaded. An application typically is implemented as a separate process with several threads of control.