资源预览内容
第1页 / 共53页
第2页 / 共53页
第3页 / 共53页
第4页 / 共53页
第5页 / 共53页
第6页 / 共53页
第7页 / 共53页
第8页 / 共53页
第9页 / 共53页
第10页 / 共53页
亲,该文档总共53页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Concurrency: Deadlock and StarvationChapter 61Deadlock Each process in a process group is waiting for some resource occupied by another process of the same group, so that every process of the group is in starvation Permanent blocking of a set of processes that either compete for system resources or communicate with each other No efficient solution Involve conflicting needs for resources by two or more processes2P1P2P3P43Process P Process Q Get AGet B Get BGet A Release A Release B Release B Release A 4Process P Process Q Get AGet B Release A Get A Get B Release B Release B Release A 5Reusable Resources Used by only one process at a time and not depleted by that use Processes obtain resources that they later release for reuse by other processes Processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores Deadlock occurs if each process holds one resource and requests the other6Example of DeadlockDeadlock would be happened if Executing sequence isp0 p1 q0 q1 p2 q27Another Example of Deadlock Space is available for allocation of 200Kbytes, and the following sequence of events occur Deadlock occurs if both processes progress to their second requestP1 . . . . .Request 80 Kbytes;Request 60 Kbytes;P2 . . . . .Request 70 Kbytes;Request 80 Kbytes;8Consumable Resources Created (produced) and destroyed (consumed) Interrupts, signals, messages, and information in I/O buffers Deadlock may occur if a Receive message is blocking May take a rare combination of events to cause deadlock9Example of Deadlock Deadlock occurs if receives are blockingP1 . . . . .Receive(P2);Send(P2, M1);P2 . . . . .Receive(P1);Send(P1, M2);10Resource Allocation Graphs Directed graph that depicts a state of the system of resources and processes11Resource Allocation Graphs12Conditions for Deadlock Mutual exclusion Only one process may use a resource at a time Hold-and-wait A process may hold allocated resources while awaiting assignment of others No preemption No resource can be forcibly removed from a process holding it13Conditions for Deadlock Circular wait a closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain consequence of the first three conditions1415Conditions for Deadlock Mutual Exclusion No preemption Hold and wait Circular wait Each of these four conditions is necessary, and four conditions taken together constitute necessary and sufficient conditions for deadlock16Deadlock Prevention Design a system in such a way that the possibility of deadlock is excluded Mutual Exclusion Impracticable, operating systems must support the feature Hold and Wait Require a process request all of its required resources at one time block the process until all requests can be granted simultaneously process may be held up for a long time waiting for all its requests resources allocated to a process may remain unused for a long time. These resources could be used by other processes 17Deadlock Prevention No Preemption If a process is denied a further request, it must release resource and request again If a process requests a resource that is currently held by another process, OS may preempt this process to require it releases its resources Practical only when the state can be easily saved and restored later, such as processors Circular Wait Define a linear ordering of resource types such that once a resource is obtained, only those resources higher in the list can be obtained May deny resources unnecessarily18Deadlock Avoidance A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock Requires knowledge of future process request19Two Approaches to Deadlock Avoidance Do not start a process if its demands might lead to deadlock Resource allocation denial: Do not grant an incremental resource request to a process if this allocation might lead to deadlock20Resource Allocation Denial Referred to as Bankers Algorithm State of the system is the current allocation of resources to process Safe state is one in which there is at least one order in which all the processes can be run to completion without resulting in a deadlock Unsafe state is a state that is not safe21Determination of a Safe State Initial StateFigure 6.7 Determination of a safe State22Determination of a Safe State P2 Runs to CompletionFigure 6.7 Determination of a safe State23Determination of a Safe State P1 Runs to CompletionFigure 6.7 Determination of a safe State24Determination of a Safe State P3 Runs to CompletionFigure 6.7 Determination of a safe State25Determination of an Unsafe StateFigure 6.8 Determination of an Unsafe State26Determination of an Unsafe StateFigure 6.8 Determination of an Unsafe
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号