Download presentation
Presentation is loading. Please wait.
Published byElijah Chandler Modified over 9 years ago
1
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks
2
7.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example System has 2 disk drives P 1 and P 2 each hold one disk drive and each needs another one
3
7.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Bridge Crossing Example Traffic only in one direction Each section of a bridge can be viewed as a resource If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback) Several cars may have to be backed up if a deadlock occurs Starvation is possible
4
7.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition System Model Resource types R 1, R 2,..., R m For example : CPU cycles, memory space, I/O devices Each resource type has instances. Each process utilizes a resource as follows: request use release
5
7.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlock Characterization Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: For example a set of processes {P 0, P 1, P 2 } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, and p2 is waiting for a resource that is held by P 0. Deadlock can arise if four conditions hold simultaneously.
6
7.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Resource-Allocation Graph V is partitioned into two types: P = {P 1, P 2, …, P n }, the set consisting of all the processes in the system R = {R 1, R 2, …, R m }, the set consisting of all resources in the system request edge – directed edge P i R j assignment edge – directed edge R j P i A set of vertices V and a set of edges E.
7
7.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Resource-Allocation Graph (Cont.) Process Resource Type with 4 instances P i requests instance of R j P i is holding an instance of R j PiPi PiPi RjRj RjRj
8
7.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of a Resource Allocation Graph With no Deadlock
9
7.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Resource Allocation Graph With A Deadlock
10
7.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Graph With A Cycle But No Deadlock
11
7.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Basic Facts If graph contains no cycles no deadlock If graph contains a cycle if only one instance per resource type, then deadlock if several instances per resource type, possibility of deadlock
12
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition
13
7.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Methods for Handling Deadlocks Deadlock Prevention. Disallow one of the four necessary conditions for deadlock. Deadlock Avoidance. Do not grant a resource request if this allocation have the potential to lead to a deadlock. Deadlock Detection. Always grant resource request when possible. Periodically check for deadlocks. If a deadlock exists, recover from it. Ignore the problem... Makes sense if the chance of deadlock is very low.
14
7.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlock Prevention Mutual Exclusion – The mutual exclusion condition must hold for non-sharable types of resources. For example, a printer cannot be simultaneously shared by several processes. Read only files are a good example of a sharable resource. If several processes attempt to open a read only file at the same time, they can be granted simultaneous access to the file. In general, however, it is not possible to prevent deadlocks by denying the mutual exclusion condition.
15
7.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlock Prevention Hold and Wait – Avoid hold and wait. must guarantee that whenever a process requests a resource, it does not hold any other resources Each process requests and be allocated all of its resources before it begins execution. A process requests resources only when it has no resources. A process may request some resources and use them. Before it can request any additional resources, however, it must release all the resources that it is currently allocated. Low resource utilization; starvation possible
16
7.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlock Prevention (Cont.) No Preemption – Avoid preemption. If the process that is holding some resources requests another resource that cannot be immediately allocated to it (i.e. the process must wait), then all resources currently being held are preempted i.e. these resources are implicitly released. The preempted resources are added to the list of resources for which the process is waiting. The process will only be restarted when it can regain its old resources, as well as the new ones that it is requesting. Circular Wait – Avoid circular wait. there exists a set {P 0, P 1, …, P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, P n–1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0.
17
7.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition
18
7.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.