If in case the requested resource is not available then we will check whether it is being used or is allocated to some other process waiting for other resources. In order to ensure that this condition does not hold the following protocols can be used :Īccording to the First Protocol: "If a process that is already holding some resources requests another resource and if the requested resources cannot be allocated to it, then it must release all the resources currently allocated to it."Īccording to the Second Protocol: "When a process requests some resources, if they are available, then allocate them. The third necessary condition for deadlocks is that there should be no preemption of resources that have already been allocated. A process that needs several popular resources may have to wait indefinitely because at least one of the resources that it needs is always allocated to some other process. Otherwise, we must request all the resources at the beginning of both protocols. In the above-given example, for instance, we can release the DVD drive and disk file and again request the disk file and printer only if we can be sure that our data will remain on the disk file. Utilization of resources may be low, since resources may be allocated but unused for a long period. After copying the disk file to the printer, the process releases these two resources as well and then terminates. The process must then again request the disk file and printer. It copies the data from the DVD drive to the disk and then releases both the DVD drive and the disk file. While the second method allows the process to request initially only the DVD drive and disk file. It will hold the printer during its entire execution, even though the printer is needed only at the end. If all the resources must be requested at the beginning of the process according to the first protocol, then the process requests the DVD drive, disk file, and printer initially. We will consider a process that mainly copies data from a DVD drive to a file on disk, sorts the file, and then prints the results to a printer. Let us illustrate the difference between these two protocols: The second protocol allows a process to request resources only when it does not occupy any resource. There are some protocols that can be used in order to ensure that the Hold and Wait condition never occurs:Īccording to the first protocol Each process must request and gets all its resources before the begining of its execution. Thus if we did not want the occurrence of this condition then we must guarantee that when a process requests a resource, it does not hold any other resource. Hold and wait condition occurs when a process holds a resource and is also waiting for some other resource in order to complete its execution. Generally, deadlocks cannot be prevented by denying the mutual exclusion condition because there are some resources that are intrinsically non-sharable. A good example of a sharable resource is Read-only files because if several processes attempt to open a read-only file at the same time, then they can be granted simultaneous access to the file.Ī process need not to wait for the sharable resource. In contrast, Sharable resources do not require mutually exclusive access and thus cannot be involved in a deadlock. For example, a printer cannot be simultaneously shared by several processes. This condition must hold for non-sharable resources. We will elaborate deadlock prevention approach by examining each of the four necessary conditions separately. The same is the situation with the deadlock if we become able to violate any condition among the four and do not let them occur together then there can be prevented from the deadlock problem. If anyone leg of the chair gets broken, then definitely it will fall. Likewise, for the deadlock problem, all the above given four conditions are needed. Let us take an example of a chair, as we know that chair always stands on its four legs. In this tutorial, we will elaborate on the deadlock prevention approach.Īs we are already familiar with all the necessary conditions for a deadlock.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |