What are the necessary conditions for deadlock?
Deadlock is a condition where two or more computer programs that must compete for the same resources, block each other thus resulting in neither one being able to function. However, deadlocks occur when these four conditions occur simultaneously:
- Mutual Exclusion – where resources shared such as read-only files do not lead to deadlocks but resources, such as printers and tape drives, requires exclusive access by a single process.
- Hold and Wait – where processes must be prevented from holding one or more resources while simultaneously waiting for one or more others.
- No Preemption – where the preemption of process resource allocations can avoid the condition of deadlocks, where ever possible.
- Circular Wait – which can be avoided if all the resources are numbers, and require that processes request resources only in strictly increasing (or decreasing) order.
If any of these conditions can be prevented then the deadlock should not occur.