Deadlocks & Livelocks Flashcards
Deadlock arises only if what four conditions hold simultaneously?
- Mutual exclusion
- Hold and Wait
- No pre-emption
- Circular wait
What is Mutual Exclusion (mutex) 3 points?
There are resources requiring mutual exclusion
* At least one resource held in a non-sharable state
* i.e. Only one process at a time can access the resource
* A requesting process must be delayed until the resource
has been released
What is Hold and Wait?
- A process is currently holding (at least one) mutex
resource - And is waiting to acquire (at least one) more that is being
held by another process
What is No Pre-emption?
- Resources cannot be pre-empted
- Resources can only be released voluntarily by the the
process holding it. - After it has completed its task
What is Circular Wait?
There exists a chain of processes P1,P2 “, … P3 such that
P1 is waiting for a mutex resource being held by P2.
* P2 for one held by P3
*P2$ for one held by Pn
* Pn for one held by P1
Options for Handling Deadlocks 3 points
- Ensure the system will never enter a deadlock state
- Allow deadlock states, but enable recovery
- Ignore the problem and pretend they never occur
Deadlock Prevention
- Mutex:
- Hold & Wait:
* Could remove by guaranteeing that when a process requests a
resource, it does not hold others
* Required process allocated all its resources before execution - No pre-emption:
* Could remove: Example – if a process requests a resource but is not
immediately allocated, it must release all other resources - Circular wait:
* Could ensure it doesn’t arise: Impose ordering on resource types,
and processes must request them strictly by this order
What to avoid Deadlock?
- Prevention ensures cannot exist though limiting
conditions - Avoidance considers resources requirements prior to
allocation
What is a safe sate?
When a process requests an available resource, the
system must decide if immediate allocation leaves the
system in a safe state
System is in a safe state if, for processes , P1,P2 “, … P3 what
conditions hold:
- If Pi resource needs are not immediately available, then Pi can wait
until all Pj(j < i) have finished - When Pj” is finished, Pi can obtain needed resources, execute, and return
allocated resources, and terminate - When Pi terminates, P i+1 can obtain its needed resources, and so on.
Safe State and Deadlock Avoidance
- If a system is in a safe state, no deadlocks
- If a system is in unsafe state, Possibility of Deadlock
- Avoidance Ensure that a system will never enter an unsafe state
How to recover from a Deadlock?
- Two main alternatives:
Process termination - Abort all processes?
- Abort individual processes until deadlock eliminated
Resource pre-emption
* Which process?
* How to rollback?
* Can cause starvation
Alternative apporach to recovering from a Deadlock?
- Ignore Deadlocks!