26 to 27deadlockavoidance

395 views
300 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
395
On SlideShare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

26 to 27deadlockavoidance

  1. 1. Understand Process Management• Deadlock Avoidance 1
  2. 2. HOME PREVIOUS TOPICNEXTPREVIOUS QUESTION PAPERSFOR OSCPP TUTORIALS 2
  3. 3. RecapIn the last class, you have learnt:• Various techniques for Deadlock Prevention namely – Denying mutual exclusion condition – Ensuring that hold and wait condition never occurs – Ensuring that no preemption of resources does not hold – Ensuring that the circular wait condition never holds 3
  4. 4. ObjectivesOn completion of this class, you would be able toknow:• Deadlock Avoidance• Safe state• Resource allocation Graph Algorithm• Banker’s Algorithm 4
  5. 5. Deadlock Avoidance• To avoid a deadlock we require additional information about how resources are to be requested• Example : – In a system with one tape drive and one printer, it needs to know that process P & Q will request which one first 5
  6. 6. Deadlock Avoidance• With this knowledge of complete sequence of requests and releases of resources for each process – It is possible to construct algorithms that ensures that the system will never enter a deadlock state• A deadlock avoidance algorithm dynamically examines that a circular wait condition can never exist 6
  7. 7. Safe State• A state is safe if the system can allocate resources to each process in some order still avoid a deadlock• A system is in a safe state only if there exists a safe sequence• A sequence of processes <P1,P2,……,Pn> is a safe sequence for the current allocation state, – if for each Pi, the resources that Pi can still request can be satisfied by the currently available resources – plus the resources held by all the Pj with j < i 7
  8. 8. Safe State unsafe deadlock safeFig – 1, Safe, unsafe and deadlock state spaces 8
  9. 9. Safe State and Unsafe State• A safe state is not a deadlock state• A deadlock state is an unsafe state• All unsafe states may not lead to a deadlock state• A system may go from a safe state to an unsafe state 9
  10. 10. Resource Allocation Graph• Here we introduce a new type of edge called claim edge• Claim edge represented by a dashed line• A claim edge Pi Rj indicates that process Pi may request resource Rj in future• When process Pi requests resource Rj, the claim edge Pi Rj is converted to a request edge 10
  11. 11. Resource Allocation Graph (contd.) R1 P1 P2 R2Fig – 2, Resource Allocation Graph for Deadlock Avoidance 11
  12. 12. Resource Allocation GraphDraw backs of resource allocation graph algorithm• Not applicable to a resource- allocation system with multiple instances of each resource type 12
  13. 13. Banker’s Algorithm• New process must declare maximum no of instances of each resource type that it may need• This number may not exceed the total no of resources in the system• When user requests a set of resources, system must determine whether allocation of these resources will retain safe state• Resources are allocated only if it leads to a safe state otherwise not allocated 13
  14. 14. Banker’s algorithm• Applicable to systems with multiple instances of each resource type• Less efficiency than the resources- allocation graph algorithm 14
  15. 15. Banker’s Algorithm R1 P1 P2 R2Fig – 3, An unsafe state in a resource allocation graph 15
  16. 16. Data Structures needed to implement the Banker’s Algorithm• Let n be the number of processes in the system• Let m be the number of resource types• The following data structures are needed 1. Available 2. Max 3. Allocation 4. Need 16
  17. 17. Data Structures needed to implement the Banker’s AlgorithmAvailable• A vector of length m indicates the number of available resources of each type• If available[j]=k, there are k instances of resource type Rj available 17
  18. 18. Data Structures needed to implement the Banker’s AlgorithmMax• An n x m matrix defines the maximum demand of each process• If Max[i,j]=k, then process Pi may request at most k instances of resource type Rj 18
  19. 19. Data Structures needed to implement the Banker’s AlgorithmAllocation• An n x m matrix defines the number of resources of each type currently allocated to each process• If Allocation[i,j]=k, then process Pi is currently allocated k instances of resource type Rj 19
  20. 20. Data Structures Needed to implement the Banker’s AlgorithmNeed• An n x m matrix indicates the remaining resource need of each process• If Need[i,j]=k, then process Pi may need k more instances of resource type Rj to complete its task• Note that Need[i,j] = Max[i,j] - Allocation[i,j] 20
  21. 21. Summary• Deadlock avoidance requires prior information on how each process will be utilizing the resources• Banker’s algorithm needs to know the maximum number of each resource type that may be requested by each process 21
  22. 22. Frequently Asked Questions1. Explain Deadlock Avoidance2. Explain Banker’s Algorithm 22
  23. 23. Quiz1. Banker’s algorithm is more efficient than resource allocation graph scheme a) True b) False2. An unsafe state always leads to a deadlock a) True b) False3. A safe state is not a deadlock state a) True b) False 23
  24. 24. Other subject materials• Web designing• Micro processors• C++ tutorials• javahome
  25. 25. Quiz4. A unsafe state is not a deadlock statea) Trueb) False 25

×