DeadLocks
Computer systems are full of resources that can only be used by one process at a time. Common examples include printers, tape drives, and slots in the system’s internal tables. Having two processes simultaneously writing to the printer leads to gibberish.
Having two processes using the same file system table slot will invariably lead to a corrupted file system. Consequently, all operating systems have the ability to (temporarily) grant a process exclusive access to certain resources. At this point both processes are blocked and will remain so forever. This situation is called a deadlock.
Deadlocks can also occur across machines. For example, many offices have a local area network with many computers connected to it. Often devices such as scanners, CD recorders, printers, and tape drives are connected to the network as shared resources,
The sequence of events required to use a resource is given below in an abstract form.
- Request the resource.
- Use the resource.
- Release the resource.
There are four conditions must hold for there to be a deadlock:
- Mutual exclusion condition. Each resource is either currently assigned to exactly one process or is available.
- Hold and wait condition. Processes currently holding resources granted earlier can request new resources.
- No preemption condition. Resources previously granted cannot be forcibly taken away from a process.
- They must be explicitly released by the process holding them.
- Circular wait condition. There must be a circular chain of two or more processes, each of which is waiting for a resource held by the next member of the chain.
DeadLoack Modelling:
This ordering does not lead to any deadlocks (because there is no competition for resources) but it also has no parallelism at all. In addition to requesting and releasing resources, processes compute and do I/O. When the processes are run sequentially, there is no possibility that while one process is waiting for I/O, another can use the CPU.
Thus running the processes strictly sequentially may not be optimal. On the other hand, if none of the processes do any I/O at all, shortest job first is better than round robin, so under some circumstances running all processes sequentially may be the best way.
Advantages of Deadlock:
Following are the advantages of deadlock:
- Advantageous to the processes that perform a single burst of activity.
- No preemption is required.
- Convenient to apply to resources that can save and restore their states easily.
- Compile-time checks help apply it feasibly
Disadvantages of Deadlock:
- Delay in process initiation.
- Knowledge of future resources is necessary.
- Frequent preemptions.
- Doesn’t allow incremental resource requests.