【文章內(nèi)容簡介】
數(shù)Scuthair=0。 Mutexchair =1。Customer i: wait(Mutexchair)。//申請對共享變量number的操作(申請占用椅子) if(number = = n1){signal(Mutexchair)。 exit。} number = number +1。 signal(Scuthair)。//給理發(fā)師發(fā)一個(gè)信號 signal(Mutexchair)。 等待理發(fā)… 理發(fā)完畢… wait(Mutexchair)。//申請對共享變量number的操作 number = number 1。 signal(Mutexchair)。 離開理發(fā)店barber: do { wait(Scuthair)。//檢查是否有顧客,無,就睡眠 給某個(gè)顧客理發(fā) } while (1)。第七章 In a real puter system, neither the resources available nor the demands of processes for resources are consistent over long periods (months). Resources break or are replaced, new processes e and go, new resources are bought and added to the system. If deadlock is controlled by the banker’s algorithm, which of the following changes can be made safely (without introducing the possibility of deadlock), and under what circumstances?(在一個(gè)真實(shí)的計(jì)算機(jī)系統(tǒng)中,無論是可用的資源還是進(jìn)程命令對資源的要求都會持續(xù)很長一段時(shí)間(幾個(gè)月)。資源損壞或被替換,新的進(jìn)程進(jìn)入和離開系統(tǒng),新的資源會被購買和添加到系統(tǒng)中。如果用銀行家算法控制死鎖,下面哪些變化是安全的(不會導(dǎo)致可能的死鎖) ,并且在什么情況下發(fā)生?)a. Increase Available (new resources added)增加可用資源(新的資源被添加到系統(tǒng))b. Decrease Available (resource permanently removed from system)減少可用資源(資源被從系統(tǒng)中永久性地移出)c. Increase Max for one process (the process needs more resources than allowed, it may want more)增加一個(gè)進(jìn)程的Max(進(jìn)程需要更多的資源,超過所允許給予的資源)d. Decrease Max for one process (the process decides it does not need that many resources)減少一個(gè)進(jìn)程的Max(進(jìn)程不再需要那么多資源)e. Increase the number of processes增加進(jìn)程的數(shù)量f. Decrease the number of processes減少進(jìn)程的數(shù)量答:作業(yè)ch8第二題 Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and released by processes only one at a time. Show that the system is deadlockfree if the following two conditions hold:(假設(shè)一個(gè)系統(tǒng)有m個(gè)資源被n個(gè)進(jìn)程共享,進(jìn)程每次只請求和釋放一個(gè)資源。證明只要系統(tǒng)符合下面兩個(gè)條件,就不會發(fā)生死鎖)a. The maximum need of each process is between 1 and m resources(每個(gè)進(jìn)程需要資源的最大值在1到m之間)b. The sum of all maximum needs is less than m + n(所有進(jìn)程需要資源的最大值的和小于m+n)答:作業(yè)ch8第三題,可以有:a.m+nb. ≥ 1 for all iProof: = ? If there exists a deadlock state then:c. = mUse a. to get:+ = m + nUse c. to get:+ m m + nRewrite to get:這意味著存在一個(gè)Pi的進(jìn)程,其= =1,那么Pi進(jìn)程至少有一個(gè)資源可以釋放。從而系統(tǒng)就不會進(jìn)入死鎖狀態(tài)。 Consider the following snapshot of a syste