Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 27 Syed Mansoor Sarwar

Similar presentations


Presentation on theme: "Lecture 27 Syed Mansoor Sarwar"— Presentation transcript:

1 Lecture 27 Syed Mansoor Sarwar
Operating Systems Lecture 27 Syed Mansoor Sarwar

2 © Copyright Virtual University of Pakistan
Agenda for Today Review of previous lecture Deadlock handling Deadlock prevention Deadlock avoidance Recap of lecture 9 April 2019 © Copyright Virtual University of Pakistan

3 © Copyright Virtual University of Pakistan
Review of Lecture 26 Dining philosophers problem with monitor Deadlocks in computers Resource allocation graph Deadlock characterization 9 April 2019 © Copyright Virtual University of Pakistan

4 © Copyright Virtual University of Pakistan
Deadlock Handling Ensure that the system will never enter a deadlock state. Allow the system to enter a deadlock state and then recover. Ignore the problem and pretend that deadlocks never occur in the system. 9 April 2019 © Copyright Virtual University of Pakistan

5 © Copyright Virtual University of Pakistan
Deadlock Handling Deadlock prevention Deadlock avoidance Deadlock detection and recovery 9 April 2019 © Copyright Virtual University of Pakistan

6 © Copyright Virtual University of Pakistan
Deadlock Prevention Restrain the ways resource allocation requests can be made to insure that at least one of the four necessary conditions is violated. 9 April 2019 © Copyright Virtual University of Pakistan

7 © Copyright Virtual University of Pakistan
Deadlock Prevention Mutual Exclusion Cannot be prevented for all resources. Some resources are inherently non-sharable because their states cannot be saved and restored without ill effects, such as a printer. 9 April 2019 © Copyright Virtual University of Pakistan

8 © Copyright Virtual University of Pakistan
Deadlock Prevention Hold and Wait – we must guarantee that whenever a process requests a resource, it does not hold any other resources. 9 April 2019 © Copyright Virtual University of Pakistan

9 © Copyright Virtual University of Pakistan
Deadlock Prevention Require a process to request and be allocated all its resources before it begins execution, or allow a process to request resources only when the process has none. Low resource utilization; starvation possible. 9 April 2019 © Copyright Virtual University of Pakistan

10 © Copyright Virtual University of Pakistan
Deadlock Prevention No Preemption If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. 9 April 2019 © Copyright Virtual University of Pakistan

11 © Copyright Virtual University of Pakistan
Deadlock Prevention Preempted resources are added to the list of resources for which the process is waiting for. Process will be restarted only when it can regain its old resources as well as the new ones that it has requested. 9 April 2019 © Copyright Virtual University of Pakistan

12 © Copyright Virtual University of Pakistan
Deadlock Prevention Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. 9 April 2019 © Copyright Virtual University of Pakistan

13 © Copyright Virtual University of Pakistan
Deadlock Prevention We assign a unique number to each resource type by using function F: R → N and make sure that processes request resources in an increasing order of enumeration. For example, tape drive = 1, disk drive = 5, and printer = 12. 9 April 2019 © Copyright Virtual University of Pakistan

14 © Copyright Virtual University of Pakistan
Deadlock Prevention Proof Let’s assume that there is a cycle P0 → P1 → P2 → … → Pk → P0 R R R Rk R0  F(R0) < F(R1) < … F(Rk) < F(R0)  F(R0) < F(R0), which is impossible  There can be no circular wait. 9 April 2019 © Copyright Virtual University of Pakistan

15 © Copyright Virtual University of Pakistan
Deadlock Avoidance Requires that the system has additional a priori information available about the use of resources by processes. Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. 9 April 2019 © Copyright Virtual University of Pakistan

16 © Copyright Virtual University of Pakistan
Deadlock Avoidance 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. 9 April 2019 © Copyright Virtual University of Pakistan

17 © Copyright Virtual University of Pakistan
Safe State When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in a safe state if there exists a safe sequence of all processes. 9 April 2019 © Copyright Virtual University of Pakistan

18 © Copyright Virtual University of Pakistan
Safe State Sequence <P1, P2, …, Pn> is safe 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. In other words, a safe sequence specifies the order in which processes can be finished. 9 April 2019 © Copyright Virtual University of Pakistan

19 © Copyright Virtual University of Pakistan
Safe State If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished. When Pj are 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. 9 April 2019 © Copyright Virtual University of Pakistan

20 © Copyright Virtual University of Pakistan
Basic Facts If a system is in safe state  no deadlocks. If a system is in unsafe state  possibility of deadlock due to the behavior of processes. Avoidance  ensure that a system never enters an unsafe state. 9 April 2019 © Copyright Virtual University of Pakistan

21 Safe, Unsafe, and Deadlock States
9 April 2019 © Copyright Virtual University of Pakistan

22 © Copyright Virtual University of Pakistan
Example System with 12 tape drives and three processes Current system state: Process Max Need Allocated P0 10 5 P1 4 2 P2 9 9 April 2019 © Copyright Virtual University of Pakistan

23 © Copyright Virtual University of Pakistan
Example System is in a safe state with the safe sequence <P1, P0, P2> P2 requests and is allocated one more tape drive. Process Max Need Allocated P0 10 5 P1 4 2 P2 9 9 April 2019 © Copyright Virtual University of Pakistan

24 © Copyright Virtual University of Pakistan
Example Assuming the the tape drive is allocated to P2, the new system state will be: Process Max Need Allocated P0 10 5 P1 4 2 P2 9 3 System gets into an unsafe state. 9 April 2019 © Copyright Virtual University of Pakistan

25 © Copyright Virtual University of Pakistan
Recap of Lecture Deadlock handling Deadlock prevention Deadlock avoidance 9 April 2019 © Copyright Virtual University of Pakistan

26 Lecture 27 Syed Mansoor Sarwar
Operating Systems Lecture 27 Syed Mansoor Sarwar


Download ppt "Lecture 27 Syed Mansoor Sarwar"

Similar presentations


Ads by Google