Ch. 6 Deadlocks
What are the 4 deadlock strategies used for dealing with deadlock?
1) Just ignore it. 2) Detection and Recovery: Let them occur, detect them, and take action. 3) Dynamic avoidance by careful resource allocation. 4) Prevention, by structurally negating one of the four conditions.
What is the banker's algorithm for multiple resources?
1) Look for a row, R, whose unmet resource needs are all smaller than or equal to A. If multiple, just pick one. If none, system will deadlock. 2) Assume process (row) finishes. Mark that process as terminated and add all of its resources to A. 3) Repeat steps 1 & 2 until either all processes are marked terminated (in which case the initial state was safe) or no process is left whose resource needs can be met (in which the system was not safe).
What are the 3 ways to recover from deadlock?
1) Recovery through preemption 2) Recovery through rollback 3) Recovery through killing processes
How are resources acquired?
A semaphore is associated with each resource. Implemented as a down on the semaphore to acquire it, and up to release it.
What is communication deadlock?
A sends a request message to process B, and then blocks until B sends back a reply message. Suppose that the request message gets lost. A is blocked waiting for the reply. B is blocked waiting for a request asking it to do something.
What is a resource?
An object granted in a deadlock.
What is livelock?
Both processes stepping away or giving up their holdings at the same time. Progress still isn't made.
What are the 2 types of deadlock detection?
Deadlock detection w/ 1 resource of each type, deadlock detection w/multiple resources of each type
What is a deadlock?
Each process in a set is waiting for an event that only another process in the set can cause.
When does one check for a deadlock?
Either every "k" minutes, or when the CPU utilization has dropped below some threshold.
How can deadlocks avoid deadlock in real life?
Ensure that one of the four deadlock conditions isn't met.
How does the Banker's algorithm work?
Extension of deadlock detection algorithm, it considers each request as it occurs, seeing whether granting it leads to a safe state. If not, it's postponed. If so, to see if a state is safe, the banker checks to see if he has enough resources to satisfy some customer. If so, these loans are assumed to be prepaid and the customers now closest to the limit is checked. If all loans can be repaid eventually, granted.
What is two-phase locking?
In the first phase, the process tries to lock all the resources it needs, one at a time. If it succeeds, it begins the second phase, performing its updates and releasing the locks. If during the first phase, some needed resource is already locked, the process just releases all its locks and starts the first phase all over. No real work is done in the first phase, just gathering resources.
What are the problems with two-phase locking?
It is not acceptable to start over if the process has read or written messages to the network, updated files, or anything else that cannot be safely repeated. The algorithm works only in those situations where the programmer has very carefully arranged things so that the program can be stopped at any point during the first phase and restarted.
Why is deadlock avoidance essentially impossible?
It requires info about future requests.
What is recovery through killing processes?
Kill processes in the deadlock cycle until the cycle is broken. Alternatively, kill a process not in the cycle to release a needed resource. This only works when a process can be rerun form the beginning with no ill effects.
What are the techniques to avoid deadlock prevention?
Mutual exclusion | spool everything Hold and wait | Request all resources initially (like in the first line of a job); all or nothing (takes a lot of time during which resources cannot be released) No preemption | Take resources away thru virtualization (takes a lot of disk space to preserve data thru spooling) Circular wait | Order resources numerically. The process cannot request a lower-numbered resource. Prevents cycles.
What are the four conditions for a resource deadlock?
Mutual exclusion: Each resource is either currently assigned to exactly 1 process or is available. Hold-and-wait: Processes currently holding resources that were granted earlier can request new resources. No-preemption: Resources previously granted cannot be forcibly taken away from a process. They must be explicitly released by the process holding them. Circular wait: There must be a circular list of two or more processes, each of which is waiting for a resource held by the next member of the chain.
What is a resource deadlock?
None of the processes can run, none of them can release any resources, and none of them can be awakened.
What are the 2 types of resources?
Preemptable: Can be taken away from the process owning it with no ill effects. Nonpreemptable: Cannot be taken away from its current owner without potentially causing failure.
What is recovery through rollback?
Processes are checkpointed frequently, meaning its resource state (what resources it currently holds) is written to a file so it can be restarted later. A sequence of checkpts accumulates for each process. To recover, a process that owns a needed resource is rolled back to a checkpt before it had that resource. All work done since that checkpt is lost.
What is the abstract sequence of events required to use a resource?
Request resource, use resource, release resource.
What is a safe state vs. an unsafe state?
Safe: There is some scheduling order in which every process can run to completion even if all of them suddenly request their maximum number of resources immediately.
What is starvation?
Some processes never getting service even though they are not deadlocked.
What is the ostrich algorithm?
Stick your head in the sand and pretend there is no problem.
What is recovery through preemption?
Take away a resource, sometimes manually, from its current owner and give it to another process. Then return it. Problem: Highly dependent on type of resource.
How can communication deadlocks be prevented?
Timeouts. In most network communication systems, whenever a message is sent to which a reply is expected, a timer is started. If the timer goes off before the reply arrives, the sender of the message assumes that the message has been lost and sends it again (and again and again if needed).