Methods for Handling Deadlocks:

We can deal with the deadlock issue in several ways:


1. We can use specific protocols to prevent or avoid deadlocks so that a system may never enter a deadlock state.


2. We can detect the deadlock and recover it.


3. We can totally ignore the deadlock problem.

Deadlock Prevention in Operating System:


We can prevent deadlocks by ensuring that at least-one of the four necessary conditions for deadlock cannot occur, If at least one condition is not satisfied, a deadlock will net occur.


1. Mutual Exclusion:


Mutual exclusion condition must hold for non-sharable resources. For example, only one process can have access to a printer at a time, otherwise the output is disturbed. Some resources can be made sharable like a read-only file. Several processes can be granted read only access to a file without interfering with each other. However, deadlock cannot be prevented by only denying the mutual exclusion condition because some resources are intrinsically non-sharable.


2. Hold and Wait:


Deadlock can be prevented by denying the hold and wait precondition. This can be implemented in two different ways.


1. One approach is that a process requests all .the resources that it needs in one single request at process startup. The system will not grant any resource in the list until it can grant all the required resources.


2. A less restrictive approach is to allow a process to request resources only when it is currently holding no resources. If a process needs a new resource, it must first release all the resources it has and then put the request. It may include a request for reallocation of a resource it just released.


Problems with This Approach:


Each of these strategies has some performance or resource utilization issues.



  • If we allocate all resources at the beginning of the process, it may hold resources when it does not need them. It reduces resource utilization. This is especially serious if a process does not know what resources it will actually need for a given execution until it has started working on the data. The process must request all the resources it might need.
  • A process that needs several popular resources might face starvation. Some processes may never execute since some other process always has control of some required resource.



3. No Preemption:


Preemption of resources means that we take away resources from processes when they are waiting for other resources. This could work in the following ways:


1. As soon as a process requests for a resource that is not available, all of its held resources are released. The process is now waiting for all of previously held resources plus the resource that it requested. Suppose a process holds a tape drive and requests a line printer. If line printer is hot available, the tape drive is taken away and the process is put into a state of waiting for both a tape drive and a line printer.

2. When a process requests a resource that is available, it gets it. Otherwise, the system checks those processes that are holding the requested resource and may be waiting for some more resources. In this case, the resource is taken away from the waiting process and allocated to the requesting process. If this cannot happen, the process has to wait. During the wait, some other process may get some of its resources.


Problems with This Approach:


It only works if the resources are preemptible. Suppose a process has printed output on a line printer and is waiting for some other resource before it can generate more output. The line printer really cannot be taken away without disturbing the output.


This scheme can also lead to starvation for a process that needs several popular resources at the same time. It may keep losing the resources it gets because they do L not all become available at the same time.


4. Circular Wait:


We can prevent deadlock by making circular wait impossible. We can define an order by which processes get resources to prevent circular wait. For example, each resource type is assigned a number. The processes can only get resources in increasing order of those resource numbers.


Suppose tape drive has number 1, disk drive has number 5 and printer has number 12. A process wants to read the disk drive and print out the results. It will first need to allocate the disk drive then the printer. It will be prevented from doing it in reverse order.


Problems with This Approach:


The problems with this approach are as follows:



  • The order of resource numbering may prove arbitrary and inconvenient. This is not very serious problem. There are often natural ways of numbering resources. For example, processes generally use input devices before output devices.
  • The order of numbering can force processes to request resources before they need them. It reduces resource utilization. Suppose a process did some work on tape before reading input from a card reader. It would still have to request the reader at the start of processing.

{ 1 comments... read them below or add one }

  1. Thank you so much for sharing about Resource Utilization. It is such a nice blog to read. Keep sharing it.

    ReplyDelete

Blog Archive

Powered by Blogger.

- Copyright © 2013 Taqi Shah Blogspot -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -