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.

126 Resource Deadlock Chapter 4AtapeprinterCBplotterFigure 4.3 Three-way deadlocka process requests it and to block the process instead, even though the resource is available.Policies that deny resources even when they are available are conservative, asopposed to the liberal policy shown earlier.<strong>An</strong>other way to picture deadlock is to draw a progress diagram such as the oneshown in Figure 4.4. In this diagram, the two dimensions refer to virtual time inprocesses A and B. Process A requires a tape drive during part of its execution and aprinter during another part. Likewise, process B requires both tape drive and printer. Letus assume that there is only one tape drive and one printer. The dashed path through thediagram shows how the processes might be scheduled. When process A is running, thepath heads to the right. When B is running, the path heads upwards. If we have only oneprocessor, there are no other possible directions for the path. The shaded regions are forbiddenbecause of resource conflicts. The region on the left must be skirted, becausethere is only one tape, and both processes need it in that region. The region on the rightmay not be entered because of conflict for the only printer.The dots in the diagram are placed at important times in the execution of theseprocesses. At point 1, process B acquires the printer. At point 2, it also gets the tape. Itreleases the printer at point 3 and the tape at point 4. Process A gets the tape at point 5and the printer at point 6. It releases them at points 7 and 8.This picture shows a safe path through the obstacle course. There is a dangerousturn, however, between points 1 and 2. If the path had continued to the right instead ofheading upward, it would not immediately enter a forbidden region. However, since thepath may never head down or left, it would have inevitably reached an obstacle thatcould not be surmounted. Virtual time would have to stop for both processes. Theywould be deadlocked. To avoid deadlock, the path must avoid the unsafe (but otherwisepermissible) region in which A has a tape and B has a printer. We will see how variousmethods achieve this goal.The most conservative approach of all is called serialization, in which processesare not allowed to have resources concurrently at all. Serialization in our two-tape examplewould result in the following scenario:

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

Saved successfully!

Ooh no, something went wrong!