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