资源预览内容
第1页 / 共38页
第2页 / 共38页
第3页 / 共38页
第4页 / 共38页
第5页 / 共38页
第6页 / 共38页
第7页 / 共38页
第8页 / 共38页
第9页 / 共38页
第10页 / 共38页
亲,该文档总共38页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Operating System,Lecture Four Multi-Threads School of Software Nanjing University,本主题教学目标,掌握多线程环境下进程和线程的概念 掌握线程的三种实现模型 了解并行处理环境,掌握SMP 了解Windows的进程和线程管理 掌握Solaris的进程和线程管理模型,Multi-Threads,Processes and Threads Symmetric Multiprocessing(SMP) Windows Threads and SMP Management Solaris Thread and SMP Management,Process,Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution- follows an execution path that may be interleaved with other processes These two characteristics are treated independently by the operating system,Process,DataBase Management System: I/O Dispatching is referred to as a thread Resource of ownership is referred to as a process or task,Multithreading,Operating system supports multiple threads of execution within a single process MS-DOS supports a single thread UNIX supports multiple user processes but only supports one thread per process Windows 2000, Solaris, Linux, Mach, and OS/2 support multiple threads,Process,Have a virtual address space which holds the process image Protected access to processors, other processes, files, and I/O resources,Thread,An execution state (running, ready, etc.) Saved thread context when not running Has an execution stack Some per-thread static storage for local variables Access to the memory and resources of its process all threads of a process share this,Benefits of Threads,Takes less time to create a new thread than a process Less time to terminate a thread than a process Less time to switch between two threads within the same process Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel,Threads,Suspending a process involves suspending all threads of the process since all threads share the same address space Termination of a process, terminates all threads within the process,Thread States,States associated with a change in thread state Spawn Spawn another thread Block Unblock Finish Deallocate register context and stacks,Remote Procedure Call Using Threads,Remote Procedure Call Using Threads,User-Level Threads,All thread management is done by the application The kernel is not aware of the existence of threads API: a program library is used to manage ULT, witch is separated from OS kernel Jacketing Blocking a thread will block a process Modify OS kernel, when a thread becomes block state by executing a system call, system call can pass the control to another thread in this process instead switching the process,Kernel-Level Threads,W2K, Linux, and OS/2 are examples of this approach Kernel maintains all information for the process and the threads Scheduling in OS is done on a thread basis OS provides a KLT API to programmers OS can be realized by multi-thread technology,ULT and KLT,ULT switching is done in user address space, this saves the overhead of mode switch Scheduling of ULT can be application specific. One application can benefit through tailored scheduling algorithm ULTs can run on any OS In a typical OS, when a thread executes a system call, the thread blocked will cause the process blocked A pure ULT application can not take advantage of multiprocessing,Combined Approaches,Example is Solaris Thread creation done in the user space Bulk of scheduling and synchronization of threads done in the user space ULTs can be mapped onto KLTs. KLTs can run parallel on multi processors. The programmer may adjust the number of KLTs to achieve the best overall results If properly deigned, this approach should combine the advantages of the pure ULT and KLT approaches while minimizing the disadvantages,Multi-Threads,Processes and Threads Symmetric Multiprocessing(SMP) Windows Threads and SMP Management Solaris Thread and SMP Management,Categories of Computer Systems,Single Instruction Single Data (SISD) single processor executes a single instruction stream to operate on data stored in a single memory Single Instruction Multiple Data (SIMD) each instruction is executed on a different set of data by the different processors,Categories of Computer Systems,Multiple Instruction Single Data (MISD) a sequence of data is transmitted to a set of processors, each of which executes a different instruction sequence. Never implemented Multiple Instruction Multiple Data (MIMD) a set of processors simultaneously execute different instruction sequences on different data sets,Symmetric Multiprocessing,Kernel can execute on any processor Typically each processor does self-scheduling form the pool of available process or threads,Multi-Threads,Processes and Threads Symmetric Multiprocessing(SMP) Windows Threads and SMP Management Solaris Thread and SMP Management,Windows 2000 Process Object,Windows 2000 Thread Object,Windows 2000 Thread States,Ready Standby Running Waiting Transition Terminated,Multi-Threads,Processes and Threads Symmetric Multiprocessing(SMP) Windows Threads and SMP Management Solaris Thread and SMP Management,Solaris,Process includes the user
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号