2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩34頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Applied Operating System Concepts,Chap 5 Threads線程,Applied Operating System Concepts,Contents內(nèi)容,Benefits 益處Thread 線程綜述User and Kernel Threads 用戶和內(nèi)核線程Multithreading Models 多線程模型Solaris 2 Threads Solari

2、s 2線程Windows2000 Threads Windows2000線程Java Threads Java線程Summary(總結(jié))Homework作業(yè),Applied Operating System Concepts,,Responsiveness 響應(yīng)Resource Sharing 資源共享Economy經(jīng)濟性Utilization of MP Architectures MP體

3、系結(jié)構(gòu)的運用,Benefits 益處,Applied Operating System Concepts,Threads線程,A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: 線程(輕型進程)是CPU運用的一個基本單元,包括program counter 程序計數(shù)器register set 寄存器

4、集stack space ??臻gA thread shares with its peer threads its: 一個線程與它的對等線程共享:code section 代碼段data section 數(shù)據(jù)段operating-system resources 操作系統(tǒng)資源collectively know as a task. 總體作為一個任務(wù)A traditional or heavyweight proces

5、s is equal to a task with one thread 傳統(tǒng)的或重型進程等價于只有一個線程的任務(wù),Applied Operating System Concepts,Threads線程(Cont.),In a multiple threaded task, while one server thread is blocked and waiting, a second thread in the same tas

6、k can run. 在一個多線程任務(wù)中,當一個服務(wù)器線程被阻塞后,在同一個任務(wù)中的第2個線程可運行Cooperation of multiple threads in same job confers higher hroughput and improved performance. 同一作業(yè)中多線程協(xié)同導致高吞吐量并改善性能Applications that require sharing a common buffer

7、(i.e., producer-consumer) benefit from thread utilization. 應(yīng)用程序需要共享一個公用的緩沖(即生產(chǎn)者-消費者),從線程運用中得利,Applied Operating System Concepts,Threads provide a mechanism that allows sequential processes to make blocking system calls

8、while also achieving parallelism. 線程提供了一種機制,允許序列進程阻塞系統(tǒng)調(diào)用同時還能實現(xiàn)并行Kernel-supported threads 內(nèi)核支持線程(Mach and OS/2). User-level threads; supported above the kernel, via a set of library calls at the user level (Project A

9、ndrew from CMU). 用戶級線程;在內(nèi)核之上,通過用戶級的庫調(diào)用Hybrid approach implements both user-level and kernel-supported threads (Solaris 2). 混合處理實現(xiàn)用戶級和內(nèi)核支持線程,Threads線程(Cont.),Applied Operating System Concepts,Thread and Process線程和進程,Sche

10、duling調(diào)度線程是調(diào)度的基本單位,同一進程中的線程切換不會引起進程切換。Concurrence并發(fā)線程可以提高系統(tǒng)的并發(fā)性。Resource資源進程擁有資源,是資源分配的基本單位,而線程則不擁有資源,但它可以訪問創(chuàng)建它的進程所擁有的資源。Context Switch上下文切換線程的上下文切換的代價比進程小。,Applied Operating System Concepts,Windows 2000 Process a

11、nd Thread Windows 2000進程和線程,Applied Operating System Concepts,Single and Multithreaded Processes單個和多線程進程,Applied Operating System Concepts,Thread and Child Process線程和子進程,,,,,Thread,Thread,Process,,,Child Process,,Appli

12、ed Operating System Concepts,User-Level Threads (ULT)用戶線程,Thread Management Done by User-Level Threads Library,such as thread creation, scheduling and management.由用戶級線程庫進行管理的線程,如線程創(chuàng)建、調(diào)度等。The kernel is unaware of user-

13、level thread, all thread creation and scheduling are done in user space without the need for kernel intervention 。內(nèi)核看不到ULT,線程的創(chuàng)建和調(diào)度在用戶空間,不需要內(nèi)核的干預(yù)。 Examples例子- POSIX Pthreads- Mach C-threads- Solaris threads,Applie

14、d Operating System Concepts,User-Level Threads用戶線程(Cont.),,,,Thread,,Thread,,Thread,Process,Process,single-threaded multi-threaded 單線程進程 多線

15、程進程運行線程的阻塞導致整個進程阻塞 運行進程的阻塞不會導致進程的阻塞,,BLOCK,,BLOCK,,cause,BLOCK,,,RUN,Process Scheduling,,,Applied Operating System Concepts,Kernel-Level Threads內(nèi)核線程,Supported by the Kernel由內(nèi)核支持KLT creation ,scheduling, and

16、management are done by the kernel in kernel space.KLT創(chuàng)建、調(diào)度和管理由內(nèi)核在核心空間運行。KLT are generally slower to create and manage than ULT. KLT創(chuàng)建和管理通常比ULT慢。Examples例子- Windows 95/98/NT - Solaris- Digital UNIX,Applied Operati

17、ng System Concepts,Multithreading Models多線程模型,Many-to-One多對一One-to-One一對一Many-to-Many 多對多,Applied Operating System Concepts,Many-to-One多對一,Many User-Level Threads Mapped to Single Kernel-Level Thread.多個用戶級線程映像進單

18、個內(nèi)核線程Multiple threads are unable to run in parallel on multiprocessor.多個線程不能并行運行在多個處理器上。Thread management is done in user space ,so it’s efficient, but the entire process will block if a thread makes a blocking system

19、call. 線程管理在用戶態(tài)執(zhí)行,因此是高效的,但一個線程的阻塞系統(tǒng)調(diào)用會導致整個進程的阻塞。 Used on Systems That Do Not Support Kernel Threads. 用于不支持內(nèi)核線程的系統(tǒng)中,Applied Operating System Concepts,Many-to-one Model多對一模型,Applied Operating System Concepts,One-to-One一

20、對一,Each User-Level Thread Maps to Kernel-Level Thread.每個用戶級線程映像進內(nèi)核線程More concurrency than the many-to-one model 比多對一模型有更好的并發(fā)性Allow multiple threads to run in parallel on multiprocessor允許多個線程并行運行在多個處理器上Creating a U

21、LT requires creating the corresponding KLT 創(chuàng)建一個ULT需要創(chuàng)建一個KLT,效率較差Examples- Windows 95/98/NT- OS/2,Applied Operating System Concepts,One-to-one Model一對一模型,Applied Operating System Concepts,Many-to-many 多對多,Many ULTs

22、maps to a smaller or equal number of KLTs.多個ULT映射為相等或小于數(shù)目的KLT.More concurrency 更好的并發(fā)性ExamplesSolarisIrixDigital UNIX,Applied Operating System Concepts,Many-to-many Model多對多模型,Applied Operating System Concepts,Sol

23、aris 2 Threads Solaris 2線程,Applied Operating System Concepts,Solaris Process Solaris 線程,Applied Operating System Concepts,Windows 2000 ThreadW2K線程,線程狀態(tài)Ready就緒:可以被調(diào)度執(zhí)行Standbly備用:下一次可以運行Running運行:執(zhí)行線程Waiting等待:由于某個

24、事件阻塞Transition轉(zhuǎn)換:準備好運行但資源不可用時,由等待進入轉(zhuǎn)換Terminated終止:運行結(jié)束。,Applied Operating System Concepts,Windows 2000 ThreadW2K線程(cont.),Applied Operating System Concepts,NT線程的有關(guān)API,CreateThread()函數(shù)在調(diào)用進程的地址空間上創(chuàng)建一個線程,以執(zhí)行指定的函數(shù);返回值為所創(chuàng)

25、建線程的句柄。ExitThread()函數(shù)用于結(jié)束本線程。SuspendThread()函數(shù)用于掛起指定的線程。ResumeThread()函數(shù)遞減指定線程的掛起計數(shù),掛起計數(shù)為0時,線程恢復(fù)執(zhí)行。,Applied Operating System Concepts,Java Threads Java線程,Java Threads May be Created by: Java線程可如下創(chuàng)建:Extending Threa

26、d class 擴充線程類Implementing the Runnable interface 實現(xiàn)可運行接口,Applied Operating System Concepts,Extending the Thread Class線程類型的擴展,class Worker1 extends Thread{public void run() {System.out.println(“I am a Wor

27、ker Thread”);}},Applied Operating System Concepts,Creating the Thread創(chuàng)建線程,public class First{public static void main(String args[]) {Worker runner = new Worker1();runner.start();System.out.println(“I am

28、 the main thread”);}},Applied Operating System Concepts,The Runnable Interface可運行接口,public interface Runnable{public abstract void run();},Applied Operating System Concepts,Implementing the Runnable Interface可運行

29、接口的實現(xiàn),class Worker2 implements Runnable{public void run() {System.out.println(“I am a Worker Thread”);}},Applied Operating System Concepts,Creating the Thread創(chuàng)建線程,public class Second{public static void main

30、(String args[]) {Runnable runner = new Worker2();Thread thrd = new Thread(runner);thrd.start();System.out.println(“I am the main thread”);}},Applied Operating System Concepts,Java Thread ManagementJava線程

31、的管理,suspend() – suspends execution of the currently running thread.掛起 - 暫停當前線程的運行sleep() – puts the currently running thread to sleep for a specified amount of time. 睡眠 - 讓當前線程入睡一段指定的時間resume() – resumes execution

32、of a suspended thread. 恢復(fù) - 再執(zhí)行被掛起的線程stop() – stops execution of a thread. 停止 - 停止一個線程的執(zhí)行,Applied Operating System Concepts,Java Thread States Java線程狀態(tài),Applied Operating System Concepts,Summary(總結(jié)),The process mo

33、del introduced in Chapter 4 assumed that a process was an executing program with a single thread of control. Many modern operating systems now provide features for a process to contain multiple threads of control. This c

34、hapter introduces many concepts associated with multithreaded computer systems and covers how to use Java to create and manipulate threads. We have found it especially useful to discuss how a Java thread maps to the thre

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論