13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

140 Resource Deadlock Chapter 4and three processes. Each of A, B, and C has one tape drive. A and B are waiting for asecond tape drive. The same cycle we saw in Figure 4.1 is present (passing through A,the tapes, B, and the tapes), but there is no deadlock. C may well finish its work andrelease its tape drive. Then either A or B can get it, finish, and let the other finish as well.In generalized resource graphs, we look for knots, which generalize cycles in ordinaryresource graphs. A knot is a set of vertices (including processes and resources)such that starting at any vertex of the knot, paths lead to all the vertices in the knot and tono vertices outside the knot. In our example, paths leading from A, B, or the tapes leadto C, but no path at all leads from C. Therefore, this graph has no knots and no deadlock.If we enlarge the example we can build a deadlock, as shown in Figure 4.11. NowC is waiting for a printer, but both printers are allocated. This graph contains a knot,namely, all the vertices except for D. All the processes in the knot are deadlocked. Terminatingany one of them will break the deadlock. For example, if we terminate C, onetape is released. Either A or B can then proceed. (Until we allocate that tape to either Aor B, we ignore the knot, because it involves a resource that is not fully allocated.)One way the resource manager can detect a knot, and therefore a deadlock, is to tryto reduce the generalized resource graph. If it can’t reduce the graph completely, thereis a knot. To reduce the graph, we remove any process that is not waiting for anyresources and any process that is waiting only for resource classes that are not fully allocated.These processes are not contributing to any deadlock; there is some chance theywill finish and return their resources. As we remove these processes from the graph, wealso remove any arrows pointing to them from resources in order to indicate that thoseresources are given back. This action may turn resources that were fully allocated beforeinto partially allocated resources, thereby allowing us to remove more processes. If wecan remove all the processes, there is no knot and no deadlock.In Figure 4.10, we would first remove C, since it is not waiting. Then the tapesresource is no longer fully allocated, so both A and B can be removed. In Figure 4.11,however, no processes can be removed, so there is a deadlock.The onset of deadlock is always at the time a process makes a request and isblocked waiting for a resource. A resource manager that depends on deadlock detectionAtapesCprintersDBFigure 4.11 A deadlocked resource graph

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!