Deadlocks occur if and only if all the four Coffman conditions are met. Preventing a deadlock is possible if any one or more of these conditions are not satisfied. Deadlock prevention is thus a very important part of the deadlock management strategies.
Elimination of the Mutual Exclusion Condition:
– The condition of the mutual exclusion condition holds good for the resources that are non – share able.
– This means that a single resource cannot be shared by a number of resources at the same time.
– It is quite difficult to eliminate this condition because some of the resources cannot be shared even inherently.
– Example of such a resource is the printer, tap drive and so on.
– One thing to be noted is that the mutually exclusive access is not required by the files with the read – only attribute.
– This is why such files do not find any involvement in the deadlock issues.
Elimination of the Hold and Wait Condition:
– This second condition can be eliminated in two ways.
– The first way is that all of the resources requested by the processes can be granted before its execution.
– The second way is preventing a process from making requests for resources if there are some resources previously allocated to it.
– It is necessary for this strategy that a process must request all the resources it requires at once.
– Then the requested resources will be granted by the system on either an all basis or a none basis.
– If the set of all resources required by the process is not currently available, the process has to wait while it may not hold any resources.
– Thus, the wait for condition is avoided and this makes one condition less for the occurrence of the deadlocks.
– But there is a drawback of this method which is that it can cause a huge wastage of resources.
– Another disadvantage is that this strategy can lead to indefinite postponement or in other words we call this as the starvation.
– This happens because all the resources might not be available to the process at once.
Elimination of the ‘Non–Preemption’ Condition:
– This condition can be prevented from occurring if process in a waiting state is forced to relinquish all the resources that it is currently holding so that they may be used by the other processes for completing their execution.
– Suppose a process is permitted to make requests for new resources while it is still holding on to some resources.
– Now what if a request is not granted.
– A resource is held by a process which might be required by another process. This results in a deadlock.
– This strategy requires that if a process is already holding a resource, it should release the previously held resource.
– If again required, the same resource might be requested again along with the additional resources.
– The non – preemptive condition can be effectively denied by the implementation of this strategy.
– One disadvantage of this method is its high cost.
– When the resources are released by a process, all its work might be lost up to that point.
– Another serious consequence of using this method is that it gives rise to the possibility of indefinite starvation.
– A process might be put on hold for an indefinite time as it makes requests and releases the same processes again and again.
Elimination of the Circular Wait Condition:
– This condition can be put off if a total ordering on all sort of resources and forcing all the threads and processes to make requests for the resources in either decreasing order or increasing order.
– With this strategy a total ordering on all types of resources is imposed.