DOC PREVIEW
LSU CSC 4103 - Deadlocks III

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1CSC 4103 - Operating SystemsFall 2009Tevfik Ko!arLouisiana State UniversityOctober 6th, 2009Lecture - XIIDeadlocks - III2Deadlock Detection• Allow system to enter deadlock state • Detection algorithm• Recovery scheme3Single Instance of Each Resource Type• Maintain wait-for graph– Nodes are processes.–Pi ! Pj if Pi is waiting for Pj. Resource-Allocation Graph Corresponding wait-for graph4Single Instance of Each Resource Type• Periodically invoke an algorithm that searches for a cycle in the graph.• An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph.• Only good for single-instance resource allocation systems.5Several Instances of a Resource Type• Available: A vector of length m indicates the number of available resources of each type.• Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process.• Request: An n x m matrix indicates the current request of each process. If Request [ij] = k, then process Pi is requesting k more instances of resource type. Rj.6Detection Algorithm1. Let Work and Finish be vectors of length m and n, respectively Initialize:(a) Work = Available(b) For i = 0,2, …, n-1, if Allocationi " 0, then Finish[i] = false;otherwise, Finish[i] = true.2. Find an index i such that both:(a) Finish[i] == false(b) Requesti # WorkIf no such i exists, go to step 4.7Detection Algorithm (Cont.)3. Work = Work + AllocationiFinish[i] = truego to step 2.4. If Finish[i] == false, for some i, 0 # i # n-1, then the system is in deadlock state. Moreover, if Finish[i] == false, then Pi is deadlocked. Algorithm requires an order of O(m x n2) operations to detect whether the system is in deadlocked state. 8Example of Detection Algorithm•Five processes P0 through P4; three resource types A (7 instances), B (2 instances), and C (6 instances).•Snapshot at time T0: Allocation Request Available A B C A B C A B C P0 0 1 0 0 0 0 0 0 0 P1 2 0 0 2 0 2 P2 3 0 3 0 0 0 P3 2 1 1 1 0 0 P4 0 0 2 0 0 2•Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i.9Example (Cont.)•P2 requests an additional instance of type C. Request A B C P0 0 0 0 P1 2 0 1 P2 0 0 1 P3 1 0 0 P4 0 0 2• State of system?–Can reclaim resources held by process P0, but insufficient resources to fulfill other processes; requests.–Deadlock exists, consisting of processes P1, P2, P3, and P4.26Recovery from Deadlock: Process Termination• Abort all deadlocked processes.• Abort one process at a time until the deadlock cycle is eliminated.• In which order should we choose to abort?– Priority of the process.– How long process has computed, and how much longer to completion.– Resources the process has used.– Resources process needs to complete.– How many processes will need to be terminated. – Is process interactive or batch?27Recovery from Deadlock: Resource Preemption• Selecting a victim – minimize cost.• Rollback – return to some safe state, restart process for that state.• Starvation – same process may always be picked as victim, include number of rollback in cost factor.3Deadlock Avoidance• Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need.• The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition.• Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.Requires that the system has some additional a priori information available.4Safe State• When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state.• System is in safe state if there exists a safe sequence of all processes. •Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j<I.–If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.–When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. –When Pi terminates, Pi+1 can obtain its needed resources, and so on. 5Basic Facts•If a system is in safe state $ no deadlocks.•If a system is in unsafe state $ possibility of deadlock.•Avoidance $ ensure that a system will never enter an unsafe state.6Safe, Unsafe , Deadlock State 7Resource-Allocation Graph Algorithm•Claim edge Pi ! Rj indicated that process Pj may request resource Rj; represented by a dashed line.• Claim edge converts to request edge when a process requests a resource.• When a resource is released by a process, assignment edge reconverts to a claim edge.• Resources must be claimed a priori in the system.8Resource-Allocation Graph For Deadlock Avoidance9Unsafe State In Resource-Allocation Graph10Banker’s Algorithm• Multiple instances.• Each process must a priori claim maximum use.• When a process requests a resource it may have to wait. • When a process gets all its resources it must return them in a finite amount of time.11Data Structures for the Banker’s Algorithm • Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available.• Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj.• Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj.•Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task.Need [i,j] = Max[i,j] – Allocation [i,j].Let n = number of processes, and m = number of resources types.12Safety Algorithm1. Let Work and Finish be vectors of length m and n, respectively. Initialize:Work = AvailableFinish [i] = false for i - 1,3, …, n.2. Find an i such that both: (a) Finish [i] = false(b) Needi # WorkIf no such i exists, go to step 4.3. Work = Work + AllocationiFinish[i] = truego to step 2.4. If Finish [i] == true for all i, then the system is in a safe state.13Resource-Request Algorithm for Process Pi Request = request vector for process Pi. If Requesti [j] = k then process Pi wants k instances of resource type Rj.1. If Requesti # Needi go to


View Full Document

LSU CSC 4103 - Deadlocks III

Download Deadlocks III
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Deadlocks III and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Deadlocks III 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?