There are some necessary conditions for deadlock to happen. They are:
1. Mutual Exclusion: Only process at a time can use the resource. Suppose p1 is holding the resource. If another process p2 requests for this resource, p2 is kept waiting. p2 is delayed until resource is released.
2. Hold and Wait: Here the process is holding one resource and it wants to acquire additional resources. These additional resources are held by other processes. So this process holds some resources and waits for other resources to be released.
3. No preemption: Resources cannot be preempted. A process must give away it’s resources voluntarily after it has done it’s job.
4. Circular Wait: Consider p0,p1,p2 all are waiting processes. p0 waits for a resource held by p1, p1 waits for resource held by p2 and p2 waits for resource held by p0.
We could predict deadlocks by using graphs called Resource Allocation Graphs.