8.1 List three examples of deadlocks that are not related to a computersystem environment.

a.兩輛車從相反方向穿過一座單行道橋。

b.一個人從梯子上下來,而另一個人在爬梯子。

c.兩列列車在同一軌道上相互靠近。

8.2 Suppose that a system is in an unsafe state. Show that it is possible for the threads to complete their execution without entering a deadlocked state.

不安全狀態不一定會導致死鎖,它只是意味著我們不能保證死鎖不會發生。因此,處於不安全狀態的系統可能仍然允許完成所有process而不發生死鎖。考慮這樣一種情況,即系統在process P0、P1和P2之間分配了12個資源。資源按照以下策略分配

目前有兩種可用資源。由於process P1可能完成,此系統處於不安全狀態,因此總共釋放了四個資源。但我們不能保證P0和P2 process 能夠完成。然而,流程可能會在請求任何進一步的資源之前釋放資源。例如,process P2可以釋放一個資源,從而將資源總數增加到五個。這允許process P0完成,這將釋放總共九個資源,從而允許process P2也完成.

8.3 Consider the following snapshot of a system:

Answer the following questions using the banker’s algorithm: 

a. What is the content of the matrix Need? 

b. Is the system in a safe state?

 c. If a request from thread T1 arrives for (0,4,2,0), can the request be granted immediately?

a、 過程P0到P4的需求值分別為(0、0、0、0)、(0、7、5、0)、(1、0、0、2)、(0、0、2、0)和(0、6、4、2)。

b、對當可用值等於(1、5、2、0)時,可以運行processP0或P3。一旦流程P3運行,它就會釋放其資源,從而允許所有其他現有流程運行。

c、這將導致可用的值為(1、1、0、0)。可以完成的process的一個順序是P0、P2、P3、P1和P4.

8.4 A possible method for preventing deadlocks is to have a single, higher-order resource that must be requested before any other resource. For example, if multiple threads attempt to access the synchronization objects A ··· E, deadlock is possible. (Such synchronization objects may include mutexes, semaphores, condition variables, and the like.) We can prevent deadlock by adding a sixth object F. Whenever a thread wants to acquire the synchronization lock for any object A ··· E, it must first acquire the lock for object F. This solution is known as containment: the locks for objects A ··· E are contained within the lock for object F. Compare this scheme with the circular-wait scheme of Section 8.5.4.

這可能不是一個好的解決方案,因為它產生的範圍太大。最好定義一個範圍盡可能窄的鎖定策略

8.5 Prove that the safety algorithm presented in Section 8.6.3 requires an order of m × n2 operations.

下圖提供了實現銀行家算法安全算法的Java代碼(銀行家算法的完整實現可通過源代碼下載獲得)。

可以看出,嵌套的外部循環都通過n次循環提供n2性能。在這些外循環中有兩個連續的內循環,循環m次。因此,該算法的為O(m×n2)。

8.6 Consider a computer system that runs 5,000 jobs per month and has no deadlock-prevention or deadlock-avoidance scheme. Deadlocks occur about twice per month, and the operator must terminate and rerun about ten jobs per deadlock. Each job is worth about two dollars (in CPU time), and the jobs terminated tend to be about half done when they are aborted. A systems programmer has estimated that a deadlock-avoidance algorithm (like the banker’s algorithm) could be installed in the system with an increase of about 10 percent in the average execution time per job. Since the machine currently has 30 percent idle time, all 5,000 jobs per month could still be run, although turnaround time would increase by about 20 percent on average. 

a. What are the arguments for installing the deadlock-avoidance algorithm? 

b. What are the arguments against installing the deadlock-avoidance algorithm?

在系統中安裝死鎖避免的一個理由是,我們可以確保死鎖永遠不會發生。此外,儘管周轉時間有所增加,但所有5000個工作崗位仍然可以運行。

反對安裝死鎖避免軟件的一個理由是,死鎖很少發生,而且發生時成本很低。

8.7 Can a system detect that some of its threads are starving? If you answer “yes,” explain how it can. If you answer “no,” explain how the system can deal with the starvation problem.

飢餓是一個很難定義的話題,因為它對於不同的系統可能意味著不同的事情。為了這個問題的目的,我們將飢餓定義為一種情況,即一個進程在收到請求的資源之前必須等待一段合理的時間,可能是無限期的。檢測飢餓的一種方法是首先確定一段時間T,這被認為是不合理的。當進程請求資源時,計時器啟動。如果經過的時間超過T,則認為該進程已飢餓。

應對飢餓的一個戰略是採取一項政策,只將資源分配給等待時間最長的進程。例如,如果進程Pa等待資源X的時間比進程Pb長,那麼來自進程Pb的請求將被延遲,直到進程Pa的請求得到滿足。

另一種策略將沒有剛才提到的那麼嚴格。在這種情況下,可以將資源授予等待時間少於另一個進程的進程,前提是另一個進程沒有飢餓。

然而,如果另一個進程被認為是飢餓的,那麼它的請求將首先得到滿足。

8.8 Consider the following resource-allocation policy. Requests for and releases of resources are allowed at any time. If a request for resources cannot be satisfied because the resources are not available, then we check any threads that are blocked waiting for resources. If a blocked thread has the desired resources, then these resources are taken away from it and are given to the requesting thread. The vector of resources for which the blocked thread is waiting is increased to include the resources that were taken away. For example, a system has three resource types, and the vector Available is initialized to (4,2,2). If thread T0 asks for (2,2,1), it gets them. If T1 asks for (1,0,1), it gets them. Then, if T0 asks for (0,0,1), it is blocked (resource not available). If T2 now asks for (2,0,0), it gets the available one (1,0,0), as well as one that was allocated to T0 (since T0 is blocked). T0’s Allocation vector goes down to (1,2,1), and its Need vector goes up to (1,0,1).

 a. Can deadlock occur? If you answer “yes,” give an example. If you answer “no,” specify which necessary condition cannot occur. 

b. Can indefinite blocking occur? Explain your answer.

a、 無法發生死鎖,因為存在搶占。

b、 是的。如果一系列請求(如process C的請求)持續搶占了process所需的所有資源,那麼process可能永遠無法獲得它所需的所有資源

 

8.9 Consider the following snapshot of a system:

Using the banker’s algorithm, determine whether or not each of the following states is unsafe. If the state is safe, illustrate the order in which the threads may complete. Otherwise, illustrate why the state is unsafe.

a. Available = (0, 3, 0, 1) 

b. Available = (1, 0, 0, 2)

a.不安全,process P2,P1,P3可以完成,但是剩下的進程無法完成

b.安全的,p1,p2,p3都能夠完成,按照這個順序,p0與p4也能完成

8.10 Suppose that you have coded the deadlock-avoidance safety algorithm that determines if a system is in a safe state or not, and now have been asked to implement the deadlock-detection algorithm. Can you do so by simply using the safety algorithm code and redefining Maxi = Waitingi + Allocationi , where Waitingi is a vector specifying the resources for which thread i is waiting and Allocationi is as defined in Section 8.6? Explain your answer

對Max向量表示process 可能發出的最大請求。在計算安全算法時,我們使用表示最大分配的需求矩陣。另一種想法是Max=Need+Allocation。根據這個問題,等待矩陣的作用類似於需求矩陣,因此Max=Waiting+ Allocation。

8.11 Is it possible to have a deadlock involving only one single-threaded process? Explain your answer.

否。占用和等待(hold and wait)條件不滿足

8.12 Draw the resource-allocation graph that illustrates deadlock from the program example shown in Figure 8.1 in Section 8.2.

8.13 Assume that a multithreaded application uses only reader–writer locks for synchronization. Applying the four necessary conditions for deadlock, is deadlock still possible if multiple reader–writer locks are used?

 是

(1)仍然保持互斥,因當有寫入者鎖無法被分享

(2)占用與等待是有可能的,因執行續可以占用一個讀取者-寫入者鎖當它同時等待其他鎖

(3)沒辦法拿走鎖,所以不可搶先

(4)循環式等待在所有執行緒中是有可能的

8.14 The program example shown in Figure 8.1 doesn’t always lead to deadlock. Describe what role the CPU scheduler plays and how it can contribute to deadlock in this program

如果thread_one在thread_two之前被調度且thread_one能夠在調度thread_two之前取得兩個鎖,死結將不會發生

死結只有在thread_one或thread_two在另一個thread獲取第二個鎖之前只能獲得一個鎖才會發生

8.15 Which of the six resource-allocation graphs shown in Figure 8.12 illustrate deadlock? For those situations that are deadlocked, provide the cycle of threads and resources. Where there is not a deadlock situation, illustrate the order in which the threads may complete execution

 

a.(a)沒有死結,因為沒有迴圈,T2會先完成,接著完成T1,T3

b.(b)有死結,T1->R3->T3->R1->T1為一個迴圈

c.(c)沒有死結,因為沒有迴圈,T3,T2會先完成接著T1

d.(d)有死結,T1->R2->T4->R1->T1為一個迴圈

e.(e)沒有死結,雖然圖裡有一個迴圈R1->T3->R2->T4->R4,若T2釋放R2,將允許T3獲取R2,即可破壞迴圈,或允許T1獲得R2,如果T1獲得R2,最後將會釋放R1與R2,將也會破壞迴圈

f.(f)沒有死結,雖然圖裡有一個迴圈T1->R2->T3->R1->T1,當T2或T4完成時,將會釋放R2,可破壞迴圈

8.16 Consider the following snapshot of a system:

What are the contents of the Need matrix?

T0:(4,2,2,1)

T1:(2,1,0,2)

T2:(4,3,0,2)

T3:(3,1,1,1)

T4:(4,2,3,1)

 

8.17 Consider the version of the dining-philosophers problem in which the chopsticks are placed at the center of the table and any two of them can be used by a philosopher. Assume that requests for chopsticks are made one at a time. Describe a simple rule for determining whether a particular request can be satisfied without causing deadlock given the current allocation of chopsticks to philosophers.

 

只有當所有哲學家都沒有兩支筷子且只剩一直筷子時,若哲學家請求的是他第一支筷子,該請求會被拒絕。

 

8.18 Consider the following snapshot of a system:

Using the banker’s algorithm, determine whether or not each of the following states is unsafe. If the state is safe, illustrate the order in which the threads may complete. Otherwise, illustrate why the state is unsafe. 

a. Available = (2, 2, 2, 3) 

b. Available = (4, 4, 1, 1) 

c. Available = (3, 0, 1, 4) 

d. Available = (1, 5, 2, 2)

a.是,若順序T4,T0,T1,T2,T3

b.是,若順序T2,T4,T3,T1,T0

c.否

d.是,若順序T3,T1,T2,T4,T0

8.19 A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their produce to the neighboring town. The bridge can become deadlocked if a northbound and a southbound farmer get on the bridge at the same time. (Vermont farmers are stubborn and are unable to back up.) Using semaphores and/or mutex locks, design an algorithm in pseudocode that prevents deadlock. Initially, do not be concerned about starvation (the situation in which northbound farmers prevent southbound farmers from using the bridge, or vice versa).

操作系統恐龍書第十版課後答案 ch08相关推荐

  1. linux安装定制添加输入,Arch Linux--定制自己的Linux操作系統(乙-國際化桌面安裝篇)...

    Arch Linux--定制自己的Linux操作系統 ----乙-國際化&桌面安裝篇 相信大家看了<甲-安裝篇>之後,Arch Linux系統已經可以正常運行了吧?不過,Arch ...

  2. [转载] JAVA语言程序设计(基础篇)第十版课后题答案(第一章)

    参考链接: Java中的Scanner和nextChar() JAVA语言程序设计(基础篇)第十版课后题答案 第一章 第二题 /** Created by ysy on 2018/7/6. */ pu ...

  3. 中國IT從業人員如此之多,為什麼沒有流行世界的核心技術呢?例如,操作系統,編程語言,數據庫等...

    工业革命与文艺复兴 18世紀中葉,英國人瓦特改良蒸汽機之後,一系列技術革命引起了從手工勞動向動力機器生產轉變的重大飛躍.隨後傳播到英格蘭到整個歐洲大陸,19世紀傳播到北美地區.工業革命的基礎,是物理和 ...

  4. Ecos操作系統查看进程信息

    由于最近公司用到了ecos操作系统,所以简单的了解了一下这个RTOS,其相关的社区资源较少,国内基本不用,这里结合手册整理了一部分的内容.本文章主要两部分,一是建立基本的测试进程,而是枚举所有进程并查 ...

  5. java第十版基础篇答案第九章_《Java语言程序设计》(基础篇原书第10版)第九章复习题答案...

    第九章 9.1:类为对象定义属性和行为,对象从类创建. 9.2:public class ClassName { } 9.3:ClassName v; 9.4:new ClassName(); 9.5 ...

  6. oracle sysoper角色,Oracle sys和system用戶、sysdba 和sysoper系統權限、sysdba和dba角色的區別...

    sys和system用戶區別 1)最重要的區別,存儲的數據的重要性不同 sys所有oracle的數據字典的基表和視圖都存放在sys用戶中,這些基表和視圖對於oracle的運行是至關重要的,由數據庫自己 ...

  7. zedboard移植linux内核,zedboard-嵌入式Linux系統移植

    1.在構建好嵌入式開發環境的基礎上進行下一步開發移植工作. 2.編譯U-Boot 首先在線獲取U-Boot源碼,在源碼include/configs/zynq_zed.h中,修改IP地址(CONFIG ...

  8. easyuefi添加linux分区,linux學習筆記(一)——使用easyBCD或easyUEFI引導從硬盤安裝Ubuntu系統...

    Table of Contents windows系統安裝ubuntu會出現引導問題,windows系統不希望有其他系統和windows系統共存.所以我們得自己作一個引導.接下來主要介紹兩種引導,ea ...

  9. (原創) Verilog入門書推薦2:數位系統實習 Quartus II (SOC) (Verilog)

    Abstract 之前曾經推薦過一本Verilog的薄書,這次再推薦一本適合FPGA與Quartus II的Verilog入門書籍. Intrduction 作者:陸自強 出版社:儒林圖書公司 語言: ...

最新文章

  1. PTA团体程序设计天梯赛-L2-010 排座位
  2. Jvm垃圾回收器(终结篇)
  3. Mac安装code blocks以及解无法打开的问题
  4. vue axios全攻略
  5. Identity和IdentityServer的区别及联系
  6. bzoj3631: [JLOI2014]松鼠的新家
  7. 11content_processor
  8. 数据库修改服务器ip地址吗,服务器数据库与改ip地址吗
  9. 微软不愿意提及的软肋:Win10的语音识别
  10. OpenGL基础35:帧缓冲(下)之简单图像处理
  11. login控件authenticate_关于asp:login控件和验证码的问题?(转)
  12. python文本词频统计是字典吗,只使用字典python3计算.txt文件中的词频
  13. muddleftpd配置和用法
  14. vmware softice
  15. python unpack原理_Python transformers.Unpack方法代码示例
  16. [蓝桥杯] 三升序列 python解法
  17. Scrapy爬虫轻松抓取网站数据
  18. 程序员员为什么总是要加班呢?不加班会被开除吗?
  19. 1、MyBatis框架入门学习CRUD
  20. 用户画像(profile v.s. persona)

热门文章

  1. java printwriter乱码_PrintWriter输出中文乱码分析与解决方案
  2. 【噪声】2. 白噪声
  3. 【20保研】2019年上海交通大学密西根学院硕士、博士招生夏令营通知
  4. mysql data文件恢复_mysql 通过data文件下来恢复数据
  5. C# listView 增 改 删 查
  6. 视频编码中的块效应、振铃效应和呼吸效应分析
  7. 基于JavaWeb的大学迎新系统设计与实现(源码+数据库脚本+论文+开题报告)
  8. 5.cisco思科模拟器ipv4和ipv6编址题目练习
  9. Android Studio ListView框架+优化安卓应用市场实例
  10. android字体变斜,TextView设置倾斜字体样式(android:textStyle=bold|italic)后,右边字显示不全...