操作系统教学课件OS_04

上传人:101****457 文档编号:50722868 上传时间:2018-08-10 格式:PPT 页数:28 大小:394.50KB
返回 下载 相关 举报
操作系统教学课件OS_04_第1页
第1页 / 共28页
操作系统教学课件OS_04_第2页
第2页 / 共28页
操作系统教学课件OS_04_第3页
第3页 / 共28页
操作系统教学课件OS_04_第4页
第4页 / 共28页
操作系统教学课件OS_04_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《操作系统教学课件OS_04》由会员分享,可在线阅读,更多相关《操作系统教学课件OS_04(28页珍藏版)》请在金锄头文库上搜索。

1、Chapter 4: ThreadsOperating System. Huan Liu. School of Software. HUSTChapter 4: Threads (线程)lOverviewlMultithreading ModelslThreading IssueslPthreadslWindows XP ThreadslLinux ThreadslJava ThreadsOperating System. Huan Liu. School of Software. HUSTSingle and Multithreaded ProcessesOperating System.

2、Huan Liu. School of Software. HUSTBenefits (P129)lResponsivenesslResource SharinglEconomylUtilization of MP ArchitecturesOperating System. Huan Liu. School of Software. HUSTUser Threads (P129)lThread management done by user-level threads library. (P131) lThree primary thread libraries:n POSIX Pthrea

3、dsn Win32 threadsn Java threadsOperating System. Huan Liu. School of Software. HUSTKernel Threads (P129)lSupported by the KernellExamplesnWindows XP/2000nSolarisnLinuxnTru64 UNIXnMac OS XOperating System. Huan Liu. School of Software. HUSTMultithreading ModelslMany-to-OnelOne-to-OnelMany-to-ManyOper

4、ating System. Huan Liu. School of Software. HUSTMany-to-One (P129,130)lMany user-level threads mapped to single kernel threadlExamples:nSolaris Green ThreadsnGNU Portable ThreadsOperating System. Huan Liu. School of Software. HUSTMany-to-One Model (P130)Operating System. Huan Liu. School of Software

5、. HUSTOne-to-One (P130)lEach user-level thread maps to kernel threadlExamplesnWindows NT/XP/2000nLinuxnSolaris 9 and laterOperating System. Huan Liu. School of Software. HUSTOne-to-one Model (P130)Operating System. Huan Liu. School of Software. HUSTMany-to-Many Model (P130)lAllows many user level th

6、reads to be mapped to many kernel threads.lAllows the operating system to create a sufficient number of kernel threads.lSolaris prior to version 9.lWindows NT/2000 with the ThreadFiber package.Operating System. Huan Liu. School of Software. HUSTMany-to-Many Model (P131)Operating System. Huan Liu. Sc

7、hool of Software. HUSTTwo-level ModellSimilar to M:M, except that it allows a user thread to be bound to kernel thread.lExamplesnIRIXnHP-UXnTru64 UNIXnSolaris 8 and earlierOperating System. Huan Liu. School of Software. HUSTTwo-level Model (P132)Operating System. Huan Liu. School of Software. HUSTTh

8、reading Issues (P138)lSemantics of fork() and exec() system callslThread cancellationlSignal handlinglThread poolslThread specific datalScheduler activationsOperating System. Huan Liu. School of Software. HUSTSemantics of fork() and exec() (P138)lDoes fork() duplicate only the calling thread or all

9、threads?Operating System. Huan Liu. School of Software. HUSTThread Cancellation (P139)lTerminating a thread before it has finished.lTwo general approaches:nAsynchronous (异步) cancellation terminates the target thread immediately.nDeferred (延期) cancellation allows the target thread to periodically (周期

10、性地) check if it should be cancelled.Operating System. Huan Liu. School of Software. HUSTSignal Handling (信号手柄) (P139)lSignals are used in UNIX systems to notify a process that a particular event has occurred.lA signal handler is used to process signals.4Signal is generated by particular event4Signal

11、 is delivered to a process4Signal is handledlOptions:nDeliver the signal to the thread to which the signal applies.nDeliver the signal to every thread in the process.nDeliver the signal to certain threads in the process.nAssign a specific thread to receive all signals for the process.Operating Syste

12、m. Huan Liu. School of Software. HUSTThread Pools (P141)lCreate a number of threads in a pool where they await work.lAdvantages:nUsually slightly faster to service a request with an existing thread than create a new thread.nAllows the number of threads in the application(s) to be bound to the size o

13、f the pool.Operating System. Huan Liu. School of Software. HUSTThread Specific Data (P142)lAllows each thread to have its own copy of data.lUseful when you do not have control over the thread creation process (i.e., when using a thread pool).Operating System. Huan Liu. School of Software. HUSTSchedu

14、ler Activations (P142)lBoth M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application.lScheduler activations provide upcalls - a communication mechanism from the kernel to the thread library.lThis communication allows an applicat

15、ion to maintain the correct number kernel threads.Operating System. Huan Liu. School of Software. HUSTPthreadslA POSIX standard (IEEE 1003.1c) API for thread creation and synchronization.lAPI specifies behavior of the thread library, implementation is up to development of the library.lCommon in UNIX

16、 operating systems (Solaris, Linux, Mac OS X).Operating System. Huan Liu. School of Software. HUSTWindows XP ThreadslImplements the one-to-one mappinglEach thread containsnA thread idnRegister setnSeparate user and kernel stacksnPrivate data storage arealThe register set, stacks, and private storage area are known as the context of the threadslThe primary data structures of a thread include:nETHREAD (executive thread block)nKTHREAD (kernel thread block)nTEB (thread en

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号