In order for a deadlock to occur, you must have all four of the following conditions met:
- Mutual Exclusion.
- Hold and Wait: Processes already holding a resource can request additional resources, without relinquishing their current resources.
- No preemption: One process cannot forcibly remove another process’ resource.
- Circular wait.
Most deadlock prevention algorithms focus on avoiding condition #4: circular wait.
– Disallow one of the four necessary conditions for deadlock
– Do not grant a resource request if this allocation have the potential to lead to a deadlock
- Mutual Exclusion
- Not here
- Hold and wait
- No wait, require a thread to request and be allocated all its resources before it begins execution, or it can only request resources when it has none
- No preemption
- If a thread is holding some resources and requesting a resource that is held, then all resources currently being held are released. But need to save the state of preempted resources.
- Circular wait
- Locks (resources) are assigned numerical values, and threads must only acquired locks that have higher numbers than locks that have already acquired.
- Let different threads acquire resources in the same order.