资源预览内容
第1页 / 共28页
第2页 / 共28页
第3页 / 共28页
第4页 / 共28页
第5页 / 共28页
第6页 / 共28页
第7页 / 共28页
第8页 / 共28页
第9页 / 共28页
第10页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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. 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 Pthreadsn 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-ManyOperating 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. 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 threads 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. School 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. HUSTThreading 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 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 (周期性地) 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 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 System. 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 of 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. HUSTScheduler 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 application 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 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号