Presentation is loading. Please wait.

Presentation is loading. Please wait.

7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources.

Similar presentations


Presentation on theme: "7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources."— Presentation transcript:

1 7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources (e.g. tape drives and optical scanners) –Cannot be removed from the processes to which they are assigned without loss of work Reentrant code –Cannot be changed while in use –May be shared by several processes simultaneously Serially reusable code –May be changed but is reinitialized each time it is used –May be used by only one process at a time

2 7.5 Four Necessary Conditions for Deadlock Mutual exclusion condition –Resource may be acquired exclusively by only one process at a time Wait-for condition (hold-and-wait condition) –Process that has acquired an exclusive resource may hold that resource while the process waits to obtain other resources No-preemption condition –Once a process has obtained a resource, the system cannot remove it from the process’s control until the process has finished using the resource Circular-wait condition –Two or more processes are locked in a “circular chain” in which each process is waiting for one or more resources that the next process in the chain is holding

3 7.6 Deadlock Solutions Four major areas of interest in deadlock research –Deadlock prevention –Deadlock avoidance –Deadlock detection –Deadlock recovery

4 7.7 Deadlock Prevention Deadlock prevention –Condition a system to remove any possibility of deadlocks occurring –Deadlock cannot occur if any one of the four necessary conditions is denied –First condition (mutual exclusion) cannot be broken

5 When denying the “wait-for condition” –All of the resources a process needs to complete its task must be requested at once –This leads to inefficient resource allocation When denying the “no-preemption” condition –Processes may lose work when resources are preempted –This can lead to substantial overhead as processes must be restarted Denying the “circular-wait” condition: –Uses a linear ordering of resources to prevent deadlock –More efficient resource utilization than the other strategies Drawbacks –Not as flexible or dynamic as desired –Requires the programmer to determine the ordering or resources for each system

6 Figure 7.5 Havender’s linear ordering of resources for preventing deadlock. 7.7.3 Denying the “Circular-Wait” Condition

7 7.8 Deadlock Avoidance with Dijkstra’s Banker’s Algorithm Banker’s Algorithm –Impose less stringent conditions than in deadlock prevention in an attempt to get better resource utilization –Safe state Operating system can guarantee that all current processes can complete their work within a finite time –Unsafe state Does not imply that the system is deadlocked, but that the OS cannot guarantee that all current processes can complete their work within a finite time

8 7.8 Deadlock Avoidance with Dijkstra’s Banker’s Algorithm Banker’s Algorithm (cont.) –Requires that resources be allocated to processes only when the allocations result in safe states. –It has a number of weaknesses (such as requiring a fixed number of processes and resources) that prevent it from being implemented in real systems

9 Figure 7.6 Safe state. 7.8.2 Example of an Unsafe State What if

10 Figure 7.7 Unsafe state. 7.8.2 Example of an Unsafe State Really?

11 7.8.3 Example of Safe-State-to- Unsafe-State Transition Safe-state-to-unsafe-state transition: –Suppose the current state of a system is safe, as shown in Fig. 7.6. –The current value of a is 2. –Now suppose that process P 3 requests an additional resource

12 Figure 7.8 Safe-state-to-unsafe-state transition. 7.8.3 Example of Safe-State-to-Unsafe-State Transition

13 7.8.5 Weaknesses in the Banker’s Algorithm Weaknesses –Requires there be a fixed number of resource to allocate –Requires the population of processes to be fixed –Requires the banker to grant all requests within “finite time” –Requires that clients repay all loans within “finite time” –Requires processes to state maximum needs in advance

14 Group Discussion 7 3/10/09 1. Dead lock prevention aims at removing any possibility of having deadlocks. The methods of DL prevention often destroys a necessary condition for DL. a. Suggest ways to destroy the first condition. Discuss good and bad. b. Suggest ways to destroy the second the condition. Discuss good and bad. c. Suggest ways to destroy the third condition. Discuss. d. Suggest ways to destroy the forth condition. Discuss. 2. In the Dinning Philosophers problem, will there be DL or IP if the eating looks like this: while (true) { think(); while (notHoldingBothFolks) { pickUpLeftFolk(); If(rightFolkNotAvailable) putDownLeftFolk(); else pickUpRightFolk(); } eat(); putDownLeftFolk(); putDownRightFolk(); }

15 3. Is this a state safe? 4. What situation can you think of when the maximum number of resources is not fixed? 5. What situation can you think of when the maximum number of processes is not fixed? 6. Is deadlock prevention better than deadlock avoidance?

16 7.9 Deadlock Detection Deadlock detection –Used in systems in which deadlocks can occur –Determines if deadlock has occurred –Identifies those processes and resources involved in the deadlock –Deadlock detection algorithms can incur significant runtime overhead

17 Figure 7.10 Resource-allocation and request graphs. 7.9.1 Resource-Allocation Graphs

18 7.9.2 Reduction of Resource-Allocation Graphs Graph reductions –If a process’s resource requests may be granted, the graph may be reduced by that process –If a graph can be reduced by all its processes, there is no deadlock –If a graph cannot be reduced by all its processes, the irreducible processes constitute the set of deadlocked processes in the graph

19 Figure 7.11 Graph reductions determining that no deadlock exists. 7.9.2 Reduction of Resource-Allocation Graphs

20 7.10 Deadlock Recovery Deadlock recovery –Clears deadlocks from system so that deadlocked processes may complete their execution and free their resources Suspend/resume mechanism –Allows system to put a temporary hold on a process –Suspended processes can be resumed without loss of work Checkpoint/rollback –Facilitates suspend/resume capabilities –Limits the loss of work to the time the last checkpoint was made

21 7.11 Deadlock Strategies in Current and Future Systems Deadlock is viewed as limited annoyance in personal computer systems –Some systems implement basic prevention methods suggested by Havender –Some others ignore the problem, because checking deadlocks would reduce systems’ performance Deadlock continues to be an important research area


Download ppt "7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources."

Similar presentations


Ads by Google