Lecture 9 - Deadlock Flashcards
What is deadlock?
Permanent blocking of a set of process because they are all waiting for each other to do something
How does deadlock usually occur?
When a set of blocked processes each holds a resource and is waiting to acquire a resource held by another process in the set
What is the difference between preemptable resources and non preemptable resources?
Preemptable - can be taken away from a process with no ill effects
non preemptable - will cause process to fail if taken away
If a resource allocation graph contains no cycles, there is no ________
deadlock
If a resource allocation graph contains a cycle, then
a) if only one instance per resource type ___________
b) if several instances per resource type _____________
definite deadlock
possible deadlock
What are the 4 conditions for deadlock?
Mutual exclusion - only one process may access the resource at a time
Hold and wait - processes hold resources already allocated to them while waiting for others
No preemption - resources only release their resources when they have finished the task
Circular wait - circular chain of processes exists
What can the OS do to deal with deadlock?
Prevent it (prevent at least one of the 4 conditions)
Dynamically avoid it - carefully allocating resources
Detect the deadlock and recover from it
Ignore it all together
How can mutual exclusion be reduced?
Make resources shareable - e.g. by spooling
How can “hold and wait” be reduced?
What is the problem with this technique?
Make processes request all resources they will ever need before starting.
Problem: process may not know what it will need when it starts
ties up resources and stops other processes from using them
What is two phase locking?
Phase I: try to lock all resources at beginning
Phase II: if successful, use the resources and release them, otherwise release all resources and start over
How can circular wait be reduced?
Assign an order to resources
Always acquire resources in that order
How does the Banker’s algorithm work?
say that the system is in a safe state iff system need not deadlock, i.e. there is some order in which the processes can execute so that each process gets all resources it needs when it starts, so it can finish and release them, and then another process can do the same etc..
If the current allocation state is safe and a process wishes to get resources:
if the next state will also be safe, grant the request
Otherwise consider another request instead
Why is detecting and recovering from deadlocks a good solution?
Awkward and costly to prevent them
How is recovery from deadlock usually done?
Kill one process at a time, attempting to save the state so it can try again later
What is the ostrich algorithm?
Ignoring deadlock problem altogether