Deadlock 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 requests Deadlock Avoidance Resource Allocation Denial Process Initiation Denial • do not grant an incremental resource request to a process if this allocation might lead to deadlock • do not start a process if its demands might lead to deadlock Referred to as the banker’s algorithm State of the system reflects the current allocation of resources to processes Safe state is one in which there is at least one sequence of resource allocations to processes that does not result in a deadlock Unsafe state is a state that is not safe Dijkstra's Banker's Algorithm Definitions Each process has a LOAN, CLAIM, MAXIMUM NEED LOAN: current number of resources held MAXIMUM NEED: total number resources needed to complete CLAIM: = (MAXIMUM - LOAN) 2.4 -5 Ceng 334 - Operating Systems Assumptions Establish a LOAN ceiling (MAXIMUM NEED) for each process MAXIMUM NEED < total number of resources available (ie., capital) Total loans for a process must be less than or equal to MAXIMUM NEED Loaned resources must be returned back in finite time 2.4 -6 Ceng 334 - Operating Systems Algorithm 1. Search for a process with a claim that can satisfied using the current number of remaining resources (ie., tentatively grant the claim) 2. If such a process is found then assume that it will return the loaned resources. 3. Update the number of remaining resources 2.4 -7 4. Repeat steps 1-3 for all processes and mark them Ceng 334 - Operating Systems DO NOT GRANT THE CLAIM if at least one process can not be marked. Implementation A resource request is only allowed if it results in a SAFE state The system is always maintained in a SAFE state so eventually all requests will be filled 2.4 -8 Ceng 334 - Operating Systems Advantages It works Allows jobs to proceed when a prevention algorithm wouldn't Problems Requires there to be a fixed number of resources What happens if a resource goes down? Does not allow the process to change its Maximum need while processing 2.4 -9 Ceng 334 - Operating Systems Determination of a Safe State State of a system consisting of four processes and three resources Allocations have been made to the four processes. Is this a safe state? Amount of existing resources Resources available after allocation P3 Runs to Completion Thus, the state defined originally is a safe state Safe and Unsafe States (1) (a) (b) (c) (d) Demonstration that the state in (a) is safe 2.4 -15 Ceng 334 - Operating Systems (e) Safe and Unsafe States (2) (a) (d) (b) Demonstration that the sate in (b) is not safe 2.4 -16 Ceng 334 - Operating Systems (c) The Banker's Algorithm for a Single Resource (a) (b) Three resource allocation states 2.4 -17 Ceng 334 - Operating Systems safe safe unsafe (c) Banker's Algorithm for Multiple Resources 2.4 -18 Example of banker's algorithm with multiple resources Ceng 334 - Operating Systems It is not necessary to preempt and rollback processes, as in deadlock detection It is less restrictive than deadlock prevention Maximum resource requirement for each process must be stated in advance Processes under consideration must be independent and with no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources Deadlock Strategies Deadlock prevention strategies are very conservative • limit access to resources by imposing restrictions on processes Deadlock detection strategies do the opposite • resource requests are granted whenever possible Deadline Detection Algorithms A check for deadlock can be made as frequently as each resource request or, less frequently, depending on how likely it is for a deadlock to occur. Tradeoffs involved in determining frequency Advantages: Frequent checks lead to early detection The algorithm is simpler if it is done more often (there have been fewer changes to the pattern of resource allocation) Disadvantage frequent checks consume considerable processor time Recovery Strategies Abort all deadlocked processes Back up each deadlocked process to some previously defined checkpoint and restart all processes Successively abort deadlocked processes until deadlock no longer exists Successively preempt resources until deadlock no longer exists Thank You
© Copyright 2025 Paperzz