操作系统精髓与设计原理Chap.ppt
《操作系统精髓与设计原理Chap.ppt》由会员分享,可在线阅读,更多相关《操作系统精髓与设计原理Chap.ppt(58页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Concurrency:Deadlock and StarvationChapter 6Outline 6.1 Principle of Deadlock6.2 Deadlock prevention(死锁预防)6.3 Deadlock avoidance(死锁避免)6.4 Deadlock detection(死锁检测)6.1 Principle of deadlockDefinition:Permanent blocking of a set of processes that either compete for system resources or communicate with
2、each otherNo efficient solutionInvolve conflicting needs for resources by two or more processes1、Reusable ResourcesUsed by one process at a time and not depleted(消耗掉消耗掉)by that useProcesses obtain resources that they later release for reuse by other processesProcessors,I/O channels,main and secondar
3、y memory,files,databases,and semaphoresDeadlock occurs if each process holds one resource and requests the otherExample of Deadlock,D&TAnother Example of DeadlockSpace is available for allocation of 200K bytes,and the following sequence of events occurDeadlock occurs if both processes progress to th
4、eir second requestP1.Request 80K bytes;Request 60K bytes;P2.Request 70K bytes;Request 80K bytes;2、Consumable ResourcesCreated(produced)and destroyed(consumed)by a processInterrupts,signals,messages,and information in I/O buffersDeadlock may occur if a Receive message is blockingMay take a rare combi
5、nation of events to cause deadlockExample of DeadlockDeadlock occurs if receive is blockingP1.Receive(P2);Send(P2,M1);P2.Receive(P1);Send(P1,M2);3、Resource Allocation GraphsDirected graph that depicts a state of the system of resources and processesResource Allocation Graphs4、Conditions for Deadlock
6、Mutual exclusion(互斥排它性访问资源)only one process may use a resource at a timeHold-and-wait(占有且等待拥有部分资源,还要请求新的)A process does not request all of its required resources at one timeConditions for DeadlockNo preemption(非剥夺性排他性访问资源)If a process holding certain resources is denied a further request,that proces
7、s must not release its original resourcesIf a process requests a resource that is currently held by another process,the operating system is not allowed to preempt the second process and require it to release its resourcesConditions for DeadlockCircular wait(循环等待在进程资源图中有环路)Possibility of DeadlockMutu
8、al ExclusionNo preemptionHold and waitExistence of DeadlockMutual ExclusionNo preemptionHold and waitCircular waitNecessary condition6.2 Deadlock PreventionIndirect method:prevent the occurrence of one of the three necessary conditions(items 1 through 3)Direct method:prevent the occurrence of a circ
9、ular wait(item 4)1、Mutual exclusionCannot be disallowed2、Hold and Wait静态分配:Resources are allocated statically,dynamic requests are not permitted.Inefficient:Be held up for a long time waiting for all its resourceResource allocated to a process may remain unused for a long time3、No Preemption剥夺调度:Whe
10、n request further resource,release its original resources first;operating system is allowed to preempt the resources held by other process.Only applied to processor or memory4、Circular wait层次分配:define a linear ordering of resource types and allocate them according to the order6.3 Deadlock AvoidanceA
11、llows the three necessary conditions but make judicious choices to assure that the deadlock point is never reached.A decision is made dynamically whether the current resource allocation request will,if granted,potentially lead to a deadlockRequires knowledge of future process requestTwo Approaches t
12、o Deadlock AvoidanceDo not start a process if its demands might lead to deadlockDo not grant an incremental resource request to a process if this allocation might lead to deadlock银行家算法银行家算法银行家拥有一笔周转资金银行家拥有一笔周转资金客户一开始必须说明其最大需求客户一开始必须说明其最大需求客户要求分期贷款,如果客户能够得到各期贷客户要求分期贷款,如果客户能够得到各期贷款,就一定能够归还贷款,否则就一定不能归款
13、,就一定能够归还贷款,否则就一定不能归还贷款还贷款只要客户所要求的最大资金量不超过总周转资只要客户所要求的最大资金量不超过总周转资金,银行家总会在有限时间内满足其需求。金,银行家总会在有限时间内满足其需求。银行家应谨慎的贷款,防止出现坏帐银行家应谨慎的贷款,防止出现坏帐用银行家算法避免死锁用银行家算法避免死锁操作系统(银行家)操作系统(银行家)操作系统管理的资源操作系统管理的资源(周转资金周转资金)进程(要求贷款的客户)进程(要求贷款的客户)Single-resourceTotal resource:10Cash=2P:2(4)Q:4(2)R:2(6)Cash=6P:2(4)R:2(6)Cas
14、h=8R:2(6)Cash=2P:2(4)Q:4(2)R:2(6)Cash=1P:4(2)Q:2(2)R:3(5)Cash=0P:5(1)Q:2(2)R:3(6)不死锁不死锁死锁死锁SafetySafetyunsafetyAnother example1、Process initiation denialOnlyRi C(n+1)i+Cki 对i=1,.,m,k=1,.,n;A new process will be started.2、Resource Allocation DenialReferred to as the bankers algorithmState of the syst
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 精髓 设计 原理 Chap
限制150内