In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the resources are not available at that time, the process enters a waiting state. Sometimes, a waiting process is never again able to change state because the resources it has requested are held by other waiting processes. This situation is called a deadlock.
A system consists of a finite number of resources to be distributed among a number of competing processes. The resources are partitioned into several types (e.g., CPU cycles, memory space, files, I/O devices).
Under the normal mode of operation, a process may utilize a resource in only the following sequence:
A deadlock situation can arise if and only if the following four conditions (often called the Coffman conditions) hold simultaneously in a system:
Deadlock Prevention provides a set of strict rules to ensure that at least one of the four necessary conditions cannot hold. By preventing just one condition, deadlocks become mathematically impossible.
We can prevent deadlocks by making all resources sharable.
We must guarantee that whenever a process requests a resource, it does not hold any other resources.
If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are preempted (taken away).
This is the most practical prevention method. We impose a total ordering of all resource types and require that each process requests resources in an increasing order of enumeration.