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

下載本文檔

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

文檔簡介

1、<p><b>  附錄一</b></p><p>  Compared to multi-threaded operating system, means is that it can run a program with the ability of different parts; each part of the implementation was as a thread

2、. Therefore, in the preparation of applications, we have very good design in order to avoid the implementation of the different threads of mutual interference. Which will help us to design robust procedures, we can make

3、at any time when necessary to add the thread. </p><p>  Thread can be described as a micro-process; it has a starting point for the implementation of the order of series and a destination. It is responsible

4、for the maintenance of its own stack, the stack for exception handling, priority scheduling and a number of other threading systems re-implementation of the information needed. From this concept, it seems there is no thr

5、ead with the process of distinction, in fact, thread and process is certainly different: the process of a complete independence t</p><p>  Therefore, a thread can not be any exclusive CPU. Occupied by each t

6、hread CPU time depends on the process and the operating system. Process assigned to each thread a short period of time that we feel all the threads are executed at the same time. In fact, the system time for each process

7、, 2 ms, and then scheduling other threads. It the same time, he maintained all the threads and circulation, the distribution of small amount of CPU time to the thread. Thread switching and scheduling is so fast t</p&g

8、t;<p>  What does scheduling mean? Scheduling processor storage means to be implemented by the end of the process of CPU time for the state and a future time loading the state of the process to resume its operatio

9、n. In this way, however there are deficiencies, one thread at any given time interruption of the implementation of a thread. Suppose a thread is a document does write operation, and another thread interrupts its operatio

10、n, also the same documents do write operation. Windows 95/NT, UNIX is used </p><p>  In non-preemptive scheduling model, each thread may need to occupy much time CPU time CPU. Scheduling in this way, it may

11、be a very long execution time makes all the other threads need to thread CPU "starving to death." In the processor is idle, that is, when the process does not use CPU, the system can allow the process of tempor

12、arily using other CPU. </p><p>  CPU occupation CPU thread has the power to control the release of only its own initiative, CPU; other threads can use the CPU. Some I / O and Windows 3.x is the use of this s

13、cheduling strategy. </p><p>  In some operating systems inside, which will use two scheduling strategy. Non-preemptive scheduling strategy of running in the thread priority when used in general, and for high

14、-priority scheduling of threads is the use of preemptive scheduling strategy. If you are unsure about the kind of system is that scheduling strategy, assuming that the scheduling strategy can not be seized is relatively

15、safe to use.</p><p>  Application in the design, we believe that those who occupy a relatively large number of CPU time for a certain interval thread will release the control of the CPU, this time the system

16、 will check the queue of those waiting inside the thread currently running with the same priority level or higher priority threads, and thread to use these CPU. If you find such a system of thread, immediately suspend th

17、e currently executing thread and activate the thread satisfy certain conditions. If you do not </p><p>  When the thread is running CPU would like to release control to a low priority thread, the current thr

18、ead into sleep state to allow low-priority threads hold the CPU. </p><p>  In a multi-processor system, the operating system will these independent threads allocated to the different processor implementation

19、, this will greatly speed up the process of running. The implementation of the efficiency of the thread will be greatly improved, because the threads of time-sharing a single processor into a distributed multi-processor

20、implementation. This multi-processor in the three-dimensional modeling and graphics processing is very useful.</p><p>  Do you need to multi-threaded? We sent a print order requesting the printer to print ta

21、sks, assuming that this time in response to the computer and the printer stopped working also, would it mean that we do things to stop waiting for this slow on the printer? Fortunately, this situation does not occur, we

22、work in the printer can also listen to music or drawing. </p><p>  Because we use a separate threads to perform these tasks. May you have multiple users’ simultaneous access to a database or web server was s

23、urprised at how they work? This is because for each connected to a database or web server user set up an independent thread to maintain the status of the user. </p><p>  If a program is running a certain deg

24、ree of order, this time in this way problem may arise, and even lead to the collapse of the entire process. If the program can be divided into different independent tasks, the use of multi-threaded, even if a certain par

25、t of the task failed, on the other would not be affected, will not lead to the collapse of the entire process. There is no doubt that the procedures for the preparation of multi-threaded tool makes you a slave to drive t

26、he process of non-multi</p><p>  If a program has a lot of threads, then the thread is bound to other programs can only take up less CPU time; and a lot of CPU time is used for thread scheduling; operating s

27、ystem also requires sufficient memory space to maintain each thread context information; therefore, a large number of threads will reduce the efficiency of system operation. Therefore, if the use of multi-threaded, then

28、the multi-threaded program must be designed well, otherwise the benefits will be far less than the disadva</p><p>  There are many ways to design multi-threaded applications. As shown in the back of the arti

29、cle, I will give detailed examples of programming, through these examples; you will be able to better understand the multi-threaded. Threads can have different priorities, for examples, in our applications there, or do a

30、 lot of graphics rendering operations at the same time to accept user input, it is clear the user's input needs to be the first time to respond to, and Rendering or you need a lot of comput</p><p>  In t

31、he above example, graphics rendering, or a lot of computing is clearly need to stop using a lot of CPU time, during this period of time, the user waiting for them there is no need to re-input information is completed, we

32、 will process designed to separate the two threads, one for the user's input, those responsible for dealing with a very long time-consuming task. This will make the procedure more flexible and can quickly respond. At

33、 the same time, users can also run any time the possibility </p><p>  We should grasp the principle of time-for those who need to compare the urgency of the task immediately, we are due to the high priority

34、given the other priorities of the threads should be lower than her priority. Client requests listener thread should always be high priority, for a user interaction with the task of the user interface; it needs to be the

35、first time responses, and its priority because of the high-priority.</p><p><b>  附錄二</b></p><p>  多線程相對于操作系統(tǒng)而言,指的是可以同時(shí)執(zhí)行同一個(gè)程序的不同部分的能力,每個(gè)執(zhí)行的部分被成為線程。所以在編寫應(yīng)用程序時(shí),我們必須得很好的設(shè)計(jì)以 避免不同的線程執(zhí)行時(shí)的相

36、互干擾。這樣有助于我們設(shè)計(jì)健壯的程序,使得我們可以在隨時(shí)需要的時(shí)候添加線程。</p><p>  線程可以被描述為一個(gè)微進(jìn)程,它擁有起點(diǎn),執(zhí)行的順序系列和一個(gè)終點(diǎn)。它負(fù)責(zé)維護(hù)自己的堆棧,這些堆棧用于異常處理,優(yōu)先級(jí)調(diào)度和其他一些系統(tǒng)重新恢復(fù)線程執(zhí)行時(shí)需要的信息。從這個(gè)概念看來,好像線程與進(jìn)程沒有任何的區(qū)別,實(shí)際上線程與進(jìn)程是肯定有區(qū)別的:一個(gè)完整的進(jìn)程擁有自己獨(dú)立的內(nèi)存空間和數(shù)據(jù),但是同一個(gè)進(jìn)程內(nèi)的線程是共享內(nèi)存

37、空間和數(shù)據(jù)的。一個(gè)進(jìn)程對應(yīng)著一段程序,它是由一些在同一個(gè)程序里面獨(dú)立的同時(shí)的運(yùn)行的線程組成的。線程有時(shí)也被稱為并行運(yùn)行在程序里的輕量級(jí)進(jìn)程,線程被稱為是輕量級(jí)進(jìn)程是因?yàn)樗倪\(yùn)行依賴與進(jìn)程提供的上下文環(huán)境,并且使用的是進(jìn)程的資源。在一個(gè)進(jìn)程里,線程的調(diào)度有搶占式或者非搶占的模式。在搶占模式下,操作系統(tǒng)負(fù)責(zé)分配cpu時(shí)間給各個(gè)進(jìn)程,一旦當(dāng)前的進(jìn)程使用完分配給自己的cpu時(shí)間,操作系統(tǒng)將決定下一個(gè)占用cpu時(shí)間的是哪一個(gè)線程。因此操作系統(tǒng)將定

38、期的中斷當(dāng)前正在執(zhí)行的線程,將cpu分配給在等待隊(duì)列的下一個(gè)線程。</p><p>  所以任何一個(gè)線程都不能獨(dú)占cpu。每個(gè)線程占用cpu的時(shí)間取決于進(jìn)程和操作系統(tǒng)。進(jìn)程分配給每個(gè)線程的時(shí)間很短,以至于我們感覺所有的線程是同時(shí)執(zhí)行的。實(shí)際上,系統(tǒng)運(yùn)行每個(gè)進(jìn)程的時(shí)間有2毫秒,然后調(diào)度其他的線程。它同時(shí)他維持著所有的線程和循環(huán),分配很少量的cpu時(shí)間給線程。線程的的切換和調(diào)度是如此之快,以至于感覺是所有的線程是同步

39、執(zhí)行的。</p><p>  調(diào)度是什么意思?調(diào)度意味著處理器存儲(chǔ)著將要執(zhí)行完cpu時(shí)間的進(jìn)程的狀態(tài)和將來某個(gè)時(shí)間裝載這個(gè)進(jìn)程的狀態(tài)而恢復(fù)其運(yùn)行。然而這種方式也有不足之處,一個(gè)線程可以在任何給定的時(shí)間中斷另外一個(gè)線程的執(zhí)行。假設(shè)一個(gè)線程正在向一個(gè)文件做寫操作,而另外一個(gè)線程中斷其運(yùn)行,也向同一個(gè)文件做寫操作。 Windows 95/NT, UNIX使用的就是這種線程調(diào)度方式。</p><p&g

40、t;  在非搶占的調(diào)度模式下,每個(gè)線程可以需要cpu多少時(shí)間就占用cpu多少時(shí)間。在這種調(diào)度方式下,可能一個(gè)執(zhí)行時(shí)間很長的線程使得其他所有需要cpu的線程”餓死”。在處理機(jī)空閑,即該進(jìn)程沒有使用時(shí)cpu,系統(tǒng)可以允許其他的進(jìn)程暫時(shí)使用cpu。</p><p>  占用cpu的線程擁有對cpu的控制權(quán),只有它自己主動(dòng)釋放cpu時(shí),其他的線程才可以使用cpu。一些I/O和Windows 3.x就是使用這種調(diào)度策略。&

41、lt;/p><p>  在有些操作系統(tǒng)里面,這兩種調(diào)度策略都會(huì)用到。非搶占的調(diào)度策略在線程運(yùn)行優(yōu)先級(jí)一般時(shí)用到,而對于高優(yōu)先級(jí)的線程調(diào)度則多采用搶占式的調(diào)度策略。如果你不確定系統(tǒng)采用的是那種調(diào)度策略,假設(shè)搶占的調(diào)度策略不可用是比較安全的。</p><p>  在設(shè)計(jì)應(yīng)用程序的時(shí)候,我們認(rèn)為那些占用cpu時(shí)間比較多的線程在一定的間隔是會(huì)釋放cpu的控制權(quán)的,這時(shí)候系統(tǒng)會(huì)查看那些在等待隊(duì)列里面的與

42、當(dāng)前運(yùn)行的線程同一優(yōu)先級(jí)或者更高的優(yōu)先級(jí)的線程,而讓這些線程得以使用cpu。如果系統(tǒng)找到一個(gè)這樣的線程,就立即暫停當(dāng)前執(zhí)行的線程和激活滿足條件的線程。如果沒有找到同一優(yōu)先級(jí)或更高級(jí)的線程,當(dāng)前線程還繼續(xù)占有cpu。</p><p>  當(dāng)正在執(zhí)行的線程想釋放cpu的控制權(quán)給一個(gè)低優(yōu)先級(jí)的線程,當(dāng)前線程就轉(zhuǎn)入睡眠狀態(tài)而讓低優(yōu)先級(jí)的線程占有cpu。</p><p>  在多處理器系統(tǒng),操作系統(tǒng)

43、會(huì)將這些獨(dú)立的線程分配給不同的處理器執(zhí)行,這樣將會(huì)大大的加快程序的運(yùn)行。線程執(zhí)行的效率也會(huì)得到很大的提高,因?yàn)閷⒕€程的分時(shí)共享單處理器變成了分布式的多處理器執(zhí)行。這種多處理器在三維建模和圖形處理是非常有用的。</p><p>  需要多線程嗎?我們發(fā)出了一個(gè)打印的命令,要求打印機(jī)進(jìn)行打印任務(wù),假設(shè)這時(shí)候計(jì)算機(jī)停止了響應(yīng)而打印機(jī)還在工作,那豈不是我們的停止手上的事情就等著這慢速的打印機(jī)打?。克业氖?,這種情況不會(huì)發(fā)

44、生,我們在打印機(jī)工作的時(shí)候還可以同時(shí)聽音樂或者畫圖。</p><p>  因?yàn)槲覀兪褂昧霜?dú)立的多線程來執(zhí)行這些任務(wù)。你可能會(huì)對多個(gè)用戶同時(shí)訪問數(shù)據(jù)庫或者web服務(wù)器感到吃驚,他們是怎么工作的?這是因?yàn)闉槊總€(gè)連接到數(shù)據(jù)庫或者web服務(wù)器的用戶建立了獨(dú)立的線程來維護(hù)用戶的狀態(tài)。</p><p>  如果一個(gè)程序的運(yùn)行有一定的順序,這時(shí)候采用這種方式可能會(huì)出現(xiàn)問題,甚至導(dǎo)致整個(gè)程序崩潰。如果程序

45、可以分成獨(dú)立的不同的任務(wù),使用多線程,即使某一部分任務(wù)失敗了,對其他的也沒有影響,不會(huì)導(dǎo)致整個(gè)程序崩潰。毫無疑問的是,編寫多線程程序使得你有了一個(gè)利器可以駕奴非多線程的程序,但是多線程也可能成為一個(gè)負(fù)擔(dān)或者需要不小的代價(jià)。如果使用的不當(dāng),會(huì)帶來更多的壞處。</p><p>  如果一個(gè)程序有很多的線程,那么其他程序的線程必然只能占用更少的cpu時(shí)間;而且大量的cpu時(shí)間是用于線程調(diào)度的;操作系統(tǒng)也需要足夠的內(nèi)存空

46、間來維護(hù)每個(gè)線程的上下文信息;因此,大量的線程會(huì)降低系統(tǒng)的運(yùn)行效率。因此,如果使用多線程的話,程序的多線程必須設(shè)計(jì)的很好,否則帶來的好處將遠(yuǎn)小于壞處。因此使用多線程我們必須小心的處理這些線程的創(chuàng)建,調(diào)度和釋放工作。</p><p>  有多種方法可以設(shè)計(jì)多線程的應(yīng)用程序。正如后面的文章所示,我將給出詳細(xì)的編程示例,通過這些例子,你將可以更好的理解多線程。線程可以有不同的優(yōu)先級(jí),舉例子來說,在我們的應(yīng)用程序里面,繪

47、制圖形或者做大量運(yùn)算的同時(shí)要接受用戶的輸入,顯然用戶的輸入需要得到第一時(shí)間的響應(yīng),而圖形繪制或者運(yùn)算則需要大量的時(shí)間,暫停一下問題不大,因此用戶輸入線程將需要高的悠閑級(jí),而圖形繪制或者運(yùn)算低優(yōu)先級(jí)即可。這些線程之間相互獨(dú)立,相互不影響。</p><p>  在上面的例子中,圖形繪制或者大量的運(yùn)算顯然是需要站用很多的cpu時(shí)間的,在這段時(shí)間,用戶沒有必要等著他們執(zhí)行完畢再輸入信息,因此我們將程序設(shè)計(jì)成獨(dú)立的兩個(gè)線程

48、,一個(gè)負(fù)責(zé)用戶的輸入,一個(gè)負(fù)責(zé)處理那些耗時(shí)很長的任務(wù)。這將使得程序更加靈活,能夠快速響應(yīng)。同時(shí)也可以使得用戶在運(yùn)行的任何時(shí)候取消任務(wù)的可能。在這個(gè)繪制圖形的例子中,程序應(yīng)該始終負(fù)責(zé)接收系統(tǒng)發(fā)來的消息。如果由于程序忙于一個(gè)任務(wù),有可能會(huì)導(dǎo)致屏幕變成空白,這顯然需要我們的程序來處理這樣的事件。所以我必須得有一個(gè)線程負(fù)責(zé)來處理這些消息,正如剛才所說的應(yīng)該觸發(fā)重畫屏幕的工作。</p><p>  我們應(yīng)該把握一個(gè)原則,對

溫馨提示

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

評(píng)論

0/150

提交評(píng)論