Explain the necessary conditions for deadlock to occur.
Conditions for deadlock to arise are:
i. Mutual exclusion: At least one resource must be held in a non-sharable mode; which is, only one process at a time can employ the resource. If other process requests which resource, the requesting process should be delayed till the resource has been released.
ii. Hold and wait: A process should be holding at least one resource and waiting to obtain additional resources which are currently being held by other processes.
iii. No pre-emption: Resources cannot be pre-empted; which is, a resource can be released only voluntarily by the process holding this, after the process holding this has completed its task.
iv. Circular wait: A set{P0, P1,......, Pn) of waiting processes should exist therefore P0 is waiting for a resource which is held through P1, P1 is waiting for a resource which is held through P2, ......., Pn-1 is waiting for a resource which is held by Pn and Pn is waiting for a resource which is held by P0.
All four conditions should hold simultaneously for a deadlock to happen and conditions are not completely independent. For illustration, the circular-wait means the hold-and- wait condition.