收藏 分销(赏)

操作系统概念英文.ppt

上传人:w****g 文档编号:14602263 上传时间:2026-10-18 格式:PPT 页数:86 大小:902.54KB 下载积分:10 金币
下载 相关
操作系统概念英文.ppt_第1页
第1页 / 共86页
操作系统概念英文.ppt_第2页
第2页 / 共86页


点击查看更多>>
资源描述
,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,2021/3/13,*,*,单击此处编辑母版标题样式,*,*,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,操作系统概念英文,操作系统概念英文操作系统概念英文An Introduction to Chapter 5(five parts)Why the thread needed,the concept of threads(4.1 Overview),thread states(Appendix 4.A),Categories and implementation(mapping)of threads(4.2),In view of programmers,multithreaded programming APIthread Libraries(4.3),2021/3/132Operating System Concepts-Chapter4 Threads-,An Introduction to Chapter 5(,five parts,),Why the thread needed,the concept of threads(4.1 Overview),thread states(Appendix 4.A),Categories and implementation(mapping)of threads(4.2),In view of programmers,multithreaded programming APIthread Libraries(4.3),2021/3/13,2,Operating System Concepts-Chapter4 Threads-,Operating-System Examples(4.5),Windows XP,Linux,Appendixes,HyperThread(HT)(Appendix 4.C),Dual-core CPU (Appendix 4.D),An Introduction to Chapter 5(cont.),2021/3/13,3,Operating System Concepts-Chapter4 Threads-,4.1.1Why thread needed,As described in Chapter 3,the process is as the,unit of resource allocation,unit of CPU scheduling,The costs of process management,such as costs of process creation,cancellation,process switch and process communication,are somewhat high,refer to Fig.3.4,and the concurrency(or multiprogramming degree)may be limited.,To reduce costs of process management and improve degrees of concurrency and parallelism,the thread is presented,4.1 Overview,2021/3/13,4,Operating System Concepts-Chapter4 Threads-,Fig.3.4,CPU Switch,From Process to Process,Kernel mode,User mode,User mode,in running state,in ready or waiting state,2021/3/13,5,Operating System Concepts-Chapter4 Threads-,In thread-supporting OS,the process is as the unit of resource allocation,while the thread as the unit of CPU scheduling and the running entity on CPU.,Merits,less costs of,thread context switching,than that of,process context switching,improving concurrency and,parallelism,less possibility of being blocked,/*程序并行执行,在多处理器系统中,线程被内核独立调度并可在多个处理器上运行。因此,当一个进程中含有多个线程时,进程可分得多个,CPU,,实现程序并行执行,Why thread needed(cont.),2021/3/13,6,Operating System Concepts-Chapter4 Threads-,Web server program P,r,multithreaded web server process,more than one thread in the process,each thread serves for a client access request,many clients can be served concurrently.,Example,2021/3/13,7,Operating System Concepts-Chapter4 Threads-,Benefits(P131),responsiveness,resource sharing,economy,utilization of multiple-processor architectures,Refer to Appendix 4.A for more details about threads,Why thread needed(cont.),2021/3/13,8,Operating System Concepts-Chapter4 Threads-,4.1 Overview,4.1.2 Basic concepts,Definition of the thread,a basic unit/,entity,of CPU utilization,that is,the basic unit/,entity,for CPU scheduling,as a part of a process and can indecently,runs on CPU,A process may contain several threads.As a basic unit for CPU scheduling,a thread in a process shares with other threads that belongs to the same process,its code section,data section and other resources,resources are allocated to the process,and all threads in this process share these resources,tread=thread ID+program counter+a register set+stack,refer to Fig.4.1 and the figure in the next slide,2021/3/13,9,Operating System Concepts-Chapter4 Threads-,Basic concepts(cont.),Traditional process,also named,heavyweight process,has a single thread of control,A thread is also called a,lightweight process,(,LWP,),线程内容,tID,程序计数器,堆栈,寄存器组,状态,子线程,进程内容,PID,地址空间,全局变量,打开文件,子进程,定时器,信号,信号量,记账信息,resource shared,by all threads in the process,+,2021/3/13,10,Operating System Concepts-Chapter4 Threads-,Fig.4.1 Single and Multithreaded Processes,more than one thread in one process,a traditional process,as a single-thread,2021/3/13,11,Operating System Concepts-Chapter4 Threads-,The threads can be identified as,user threads,or user-level threads(ULT),kernel threads,or kernel-level threads(KLT),User Threads,thread management(creating,scheduling,.)is conducted by the user-level,threads library,or by programming environments(midewares),OS,may be still process-based,Three primary thread libraries,POSIX Pthreads,Win32 threads,Java threads,4.2 Multithreading Models,2021/3/13,12,Operating System Concepts-Chapter4 Threads-,Kernel threads,supported by the kernel,OS is responsible for thread management,Examples,Windows XP/2000,Solaris,Linux?,Tru64 UNIX,Mac OS X,In some systems,there exists KLT and ULT simultaneously.,Multithreading Models(cont.),2021/3/13,13,Operating System Concepts-Chapter4 Threads-,In the system supporting kernel threads,OS scheduler assigns CPU to kernel threads.For the user-level threads,how to occupy the CPU?,How to implement ULTs by KLTs,mapping between user threads and kernel threads,Multithreading Models(cont.),2021/3/13,14,Operating System Concepts-Chapter4 Threads-,Fig.5.0.3 Solaris 2 Threads,2021/3/13,15,Operating System Concepts-Chapter4 Threads-,u,L,线程库,k,u,线程 库,u,u,L,L,k,k,u,线程 库,u,u,L,L,k,k,u,L,k,u,L,线程库,k,u,线程调度程序,CPU,CPU,CPU,CPU,CPU,进程,1,进程,2,进程,4,进程,5,硬,件,内核空间,用户空间,u,L,线程库,k,u,进程,3,L,k,例。,Window XP +Java Run-time System,2021/3/13,16,Operating System Concepts-Chapter4 Threads-,4.2.1 Many-to-One,Many user-level threads mapped to single kernel thread/process.,refer to Fig.4.2,e.g.GNU Portable Threads,Green threads for Solaris2,Demerit,blocking of one thread in a process results in the whole process being blocked,less concurrency and less parallelism,Multithreading Models(cont.),2021/3/13,17,Operating System Concepts-Chapter4 Threads-,Fig.4.2 Many-to-One Model,/process,2021/3/13,18,Operating System Concepts-Chapter4 Threads-,4.2.2 One-to-one,Merits:more concurrency and parallelism,Demerits:overhead for thread managements,E.g.Windows NT/XP/2000,Solaris 9 and later,Fig.4.3 One-to-One Model,Multithreading Models(cont.),2021/3/13,19,Operating System Concepts-Chapter4 Threads-,4.2.3 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.,E.g.,solaris prior to version 9,windows NT/2000 with the,ThreadFiber,package,4.2 Multithreading Models(cont.),2021/3/13,20,Operating System Concepts-Chapter4 Threads-,Fig.4.3 Many-to-Many Model,2021/3/13,21,Operating System Concepts-Chapter4 Threads-,A thread library provides the programmer an API for creating and managing threads,Two approaches for thread library implementation,The first approach,provide a library entirely in user space with no kernel support,codes and data structures for the threads exist in user space,invoking a function in the library results in a local function call in user space,4.3 Thread Libraries,2021/3/13,22,Operating System Concepts-Chapter4 Threads-,The second approach,implement a kernel-level library support directly by OS,codes and data structures for the threads exist in kernel space,invoking a function in the API for the library results in a system call to the kernel,Three thread libraries being in use today,Pthreads,Win32,Java,Thread Libraries(cont.),2021/3/13,23,Operating System Concepts-Chapter4 Threads-,Pthreads,a specification for thread behavior,on the basis of POSIX standard(IEEE 1003.1C),for programmer,it defines an API for thread creation and synchronization,may be provided as either a user-or kernel-level library,common in UNIX operating systems(Solaris,Linux,Mac OS X),not by Windows,Win32 threads,kernel-level thread library available on Windows systems,Thread Libraries(cont.),2021/3/13,24,Operating System Concepts-Chapter4 Threads-,Windows XP Threads,Implement the one-to-one mapping,Each thread contains,a thread id,register set,separate user and kernel stacks,private data storage area,The register set,stacks,and private storage area are known as the,context,of the threads,The primary data structures of a thread include:,ETHREAD(executive thread block),KTHREAD(kernel thread block),TEB(thread environment block),2021/3/13,25,Operating System Concepts-Chapter4 Threads-,Java thread library,supporting thread creating and management in Java environments,managed by JVM,the Java thread API is typically implemented using a thread library available on the host system,e.g.on Windows systems,Java threads are implemented using the Win32 API,Thread Libraries(cont.),2021/3/13,26,Operating System Concepts-Chapter4 Threads-,Java Thread States,2021/3/13,27,Operating System Concepts-Chapter4 Threads-,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),/*,严格意义上,Linux,只支持进程,并不支持线程.因为,Linux,中只有进程的,PCB,所对应的,task_struc,没有线程的,TCB.,for more details,refer to the appendix for Linux thread,in,Linux as Case Studies,2021/3/13,28,Operating System Concepts-Chapter4 Threads-,4.4 Threading Issues,Some issues related to multithread programming,4.4.1 The fork()and exec()system calls,If one thread in the parent process P1 calls,fork,to create a new child process P2,the new process P2 will,duplicate all threads in the parent process,or,duplicate only the thread who create it,and becomes a single-thread process,process P1,P2,process P1,P2,2021/3/13,29,Operating System Concepts-Chapter4 Threads-,4.3.2 Thread cancellation(P139),Target thread,the thread to be cancelled,Cancellation of,target thread,in two scenarios,asynchronous cancellation,one thread immediately terminates the target thread,deferred cancellation,the target thread periodically checks whether it should terminate,allowing it an opportunity to terminate itself in an orderly fashion,such as waiting for the terminating of its child threads,Troublesome in asynchronous cancellation,Threading Issues(cont.),2021/3/13,30,Operating System Concepts-Chapter4 Threads-,4.4.3 Signal(,信号),handling(*,掌握*),Definition in Unix,a facility to notify a process that a particular event occurred.,event-driven mechanism,Handling of signals in OS,a signal is generated by the occurrence of a particular event,a generated signal is delivered to a process,once delivered,the signals must be handled,Signals vs interrupts,the interrupt is processed by CPU,the signal is processed by OS,Threading Issues(cont.),2021/3/13,31,Operating System Concepts-Chapter4 Threads-,Two types of signal,synchronous signals,generated by an internal event in the running/receiver process,e.g.illegal memory access,division by zero,trap?,asynchronous signals,generated by an event external to a running/receiver process,e.g.terminating a process with,or having a timer expire,Each signal can be handled by,a default signal,handler,that is run by the kernel,or,a user-defined signal handler,For more details about Linux signals,refer to the appendix about Linux process management and IPC,in,Linux as Case Studies,Signal Handling,(cont.),2021/3/13,32,Operating System Concepts-Chapter4 Threads-,Windows2000 has a IPC mechanism,called,asynchronous procedure calls,(,APCs,),similar to asynchronous signal in Unix.,Signal Handling,(cont.),2021/3/13,33,Operating System Concepts-Chapter4 Threads-,4.4.4 Thread Pools,Thread pool,a set of pre-created threads,the number of threads in this set is limited.,used to bound the number of threads concurrently active in the system,E.g.In a multithreading web server,one service request from outside creates one thread;the number of threads in web server process is dynamic changing.,pool,request,running,awaken,cpu allocation,completion,Threading Issues(cont.),2021/3/13,34,Operating System Concepts-Chapter4 Threads-,4.4.5 Thread-specific data,As shown in ,data in threads includes,shared data,thread-specific data,Threading Issues(cont.),2021/3/13,35,Operating System Concepts-Chapter4 Threads-,1.为什么引入线程,操作系统中引入进程是为了支持多道程序的并发执行,提高程序运行效率和系统资源利用率,传统基于进程的操作系统(又称作单线程结构进程)给并发程序设计效率带来问题,进程切换时进程管理的时空开销过大,频繁的进程调度消耗,CPU,时间,为每个进程分配存储空间限制了操作系统,中进程的总数,进程通信代价大,进程之间的并发性粒度较粗,并发度不高,不适合并行计算和分布并行计算的要求,不适合客户/服务器计算的要求,Appendix 4.A,关于线程,2021/3/13,36,Operating System Concepts-Chapter4 Threads-,进程控制块,进 程,用户地址空间,用户堆栈,系统堆栈,管理者,执行序列,单(线程)进程(模型),用户,地址空间,进程,控制块,用户,堆栈,系统,堆栈,单(线程)进程的内存布局和运行,2021/3/13,37,Operating System Concepts-Chapter4 Threads-,解决问题的基本思路,把进程的两项功能“独立分配资源”与“被调度分派执行”分离开,进程作为系统资源分配和保护的独立单位,不需要频繁地切换,一个进程可以包含多个线程,线程作为系统调度和分派的基本单位,能轻装运行,会被频繁地调度和切换,在这种指导思想下,产生了线程的概念,2021/3/13,38,Operating System Concepts-Chapter4 Threads-,管理和执行相分离的进程模型,用户堆栈,系统堆栈,执行控制,进程,进程控制块,用户地址空间,共 享,执行序列,管理者,执行序列,用户堆栈,系统堆栈,执行控制,2021/3/13,39,Operating System Concepts-Chapter4 Threads-,多线程进程的内存布局,多线程进程模型,用户,地址空间,进程,控制块,线程控制块,系统,堆栈,用户,堆栈,线程1,线程控制块,系统,堆栈,用户,堆栈,线程,N,2021/3/13,40,Operating System Concepts-Chapter4 Threads-,线程内容,t_ID,程序计数器,堆栈,寄存器组,状态,子线程,进程内容,P_ID,地址空间,全局变量,打开文件,子进程,定时器,信号,信号量,记账信息,resource shared,by all threads in the process,+,进程和线程内容,2021/3/13,41,Operating System Concepts-Chapter4 Threads-,线程的内存布局,进 程,地址空间,线,程,1,共 享,空 间,线,程,2,线,程,n,线 程,2021/3/13,42,Operating System Concepts-Chapter4 Threads-,2.基本概念,Thread,定义,进程内一个相对独立的、可执行单元,是进行处理器调度和分派的基本单位,使用进程分配给它的资源和环境,线程的性质,进程内相对独立的可执行单元,类似于应用中子任务的执行,OS,基本调度单元,包含调度所需信息,进程的执行体现为进程内线程的执行,创建进程时创建进程内的线程,线程可创建其它线程。,Appendix 4.A,关于线程(续,),2021/3/13,43,Operating System Concepts-Chapter4 Threads-,进程拥有资源,同一进程内的线程共享并使用资源。,共享资源的线程间的通信和同步机制,线程的生命周期和状态变化,Appendix 4.A,关于线程(续,),2021/3/13,44,Operating System Concepts-Chapter4 Threads-,进程,是操作系统中,进行保护和资源分配的基本单位,。,它具有:,一个虚拟地址空间,用来容纳进程的映像,对处理器、其它(通信的)进程、文件和,I/O,资源等的存取保护机制,多线程环境中进程的定义,2021/3/13,45,Operating System Concepts-Chapter4 Threads-,多线程环境中的线程概念,线程,是操作系统进程中能够独立执行的实体(控制流),,是处理器调度和分派的基本单位,。线程是进程的组成部分,每个进程内允许包含多个并发执行的实体(控制流),这就是多线程。,2021/3/13,46,Operating System Concepts-Chapter4 Threads-,线程的优点,一个进程内的多个线程驻留同一地址空间,共享数据和文件,线程创建,/,撤销的代价比进程创建,/,撤销的代价小,提高了并发程序执行效率,CPU,在线程间的切换比在进程间的切换的代价小,线程间通信的有效性,方便简化用户的程序结构工作,支持多线程机制的语言和开发环境,Java,。,Appendix 4.A,关于线程(续,),2021/3/13,47,Operating System Concepts-Chapter4 Threads-,3.线程的状态和管理,3,个基本状态,就绪,运行,等待,/,阻塞,与进程区别,无挂起状态,线程不是资源拥有者,无权决定从主存中撤出。,进程内某个线程阻塞时,整个进程并不阻塞,进程内其它线程仍维持原各自状态,参与调度。,进程不是基本调度单位,只有活动,/,可运行和非活动,/,不可运行,2,类状态,如,Windows NT,。,Appendix 4.A,关于线程(续,),2021/3/13,48,Operating System Concepts-Chapter4 Threads-,新线程,死亡,不可运行,Newthread(),Start(),Stop(),等待事件,Stop()or,Exit,图,4.1 Java,线程状态状态,可运行,Stop(),Yield(),Appendix 4.A,关于线程(续,),2021/3/13,49,Operating System Concepts-Chapter4 Threads-,线程管理原语,创建,fork(),,撤销,Finish/Exit/stop,,阻塞,/,等待,Block/wait,,,恢复,/,解挂,Resume/Unblock/,Unsuspend,改变优先级,Java Run-time System,线程组(,Thread Group),多个对象的集合,作为一个进程组对象统一管理,如一起创建或挂起。进程组具有自己的特性和安全保密方法。,Appendix 4.A,关于线程(续,),2021/3/13,50,Operating System Concepts-Chapter4 Threads-,4.线程描述,进程,资源分配单元,地址空间,装有,进程映象(,process image),线程,状态,,现场信息(,PC,,,PSW,,通用,R,,堆栈指针),,执行堆栈,主存区(存放线程局部变量),),线程可以访问被进程中所有线程共享的该进程的主存和资源,引入线程控制块,TCB,,利用,PCB,和,TCB,共同描述进程和线程的各种属性及调度信息。,TCB,链接与线程队列,Appendix 4.A,关于线程(续,),2021/3/13,51,Operating System Concepts-Chapter4 Threads-,Appendix B Windows 2000/NT Threads,Windows NT,的,CPU,管理模型的特点,多任务(多进程)、多线程、对称多处理器,NT,体现为多个,服务器,进程,,每个服务器进程使用多个,线程,来处理同时从多个客户来的请求,NT,进程、线程均被作为对象实现,并通过对象服务访问,NT,进程管理程序在它所管理的子进程之间不具有父进程/子进程或其他关系,进程间共享对象的优越功能,灵活的内部进程通信能力,进程对象和线程对象都具有内部同步能力,2021/3/1
展开阅读全文

开通  VIP、SVIP  下载更划算
下载10份以上建议开通 VIP 会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        关注我们

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服