Question

In: Computer Science

handling deadlock

Consider the following ways of handling deadlock:
(1) Banker’s algorithm,
(2) Detect deadlock and kill thread, releasing all resources,
(3) Reserve all resources in advance,
(4) Restart thread and release all resources if thread needs to wait,
(5) Resource ordering, and
(6) Detect deadlock and roll back thread’s actions.
a. One criterion to use in evaluating different approaches to deadlock is which approach permits the greatest concurrency. In other words, which approach allows the most threads to make progress without waiting when there is no deadlock? Give a rank order from 1 to 6 for each of the ways of handling deadlock just listed, where 1 allows the greatest degree of concurrency. Comment on your ordering.
b. Another criterion is efficiency; in other words, which requires the least processor overhead. Rank order the approaches from 1 to 6, with 1 being the most efficient, assuming that deadlock is a very rare event. Comment on your ordering. Does your ordering change if deadlocks occur frequently?

Solutions

Expert Solution

a.    In order from most-concurrent to least, there is a rough partial order on the deadlock-handling algorithms:

 

 

 

  1. Detect deadlock and kill thread, releasing its resources detect deadlock and roll back thread's actions

     

Restart thread and release all resources if thread needs to wait

 

None of these algorithms limit concurrency before deadlock occurs, because they rely on runtime checks rather than static restrictions. Their effects after deadlock is detected are harder to characterize: they still allow lots of concurrency (in some cases they enhance it), but the computation may no longer be sensible or efficient. The third algorithm is the strangest, since so much of its concurrency will be useless repetition; because threads compete for execution time, this algorithm also prevents useful computation from advancing. Hence it is listed twice in this ordering, at both extremes.

 

 

 

  1. Banker's algorithm

     

Resource ordering

 

 

These algorithms cause more unnecessary waiting than the previous two by restricting the range of allowable computations. The banker's algorithm prevents unsafe allocations (a proper superset of deadlock-producing allocations) and resource ordering restricts allocation sequences so that threads have fewer options as to whether they must wait or not.

 

 

 

  1. Reserve all resources in advance

     

This algorithm allows less concurrency than the previous two, but is less pathological than the worst one. By reserving all resources in advance, threads have to wait longer and are more likely to block other threads while they work, so the system-wide execution is in effect more linear.

 

 

 

  1. Restart thread and release all resources if thread needs to wait As noted above, this algorithm has the dubious distinction of allowing both the most and the least amount of concurrency, depending on the definition of concurrency.

     

 

b.   In order from most-efficient to least, there is a rough partial order on the deadlock-handling algorithms:

 

 

 

  1. Reserve all resources in advance

     

Resource ordering

 

 

These algorithms are most efficient because they involve no runtime overhead. Notice that this is a result of the same static restrictions that made these rank poorly in concurrency.

 

 

 

  1. Banker's algorithm

     

Detect deadlock and kill thread, releasing its resources

 

 

 

These algorithms involve runtime checks on allocations which are roughly equivalent; the banker's algorithm performs a search to verify safety which is O(n m) in the number of threads and allocations, and deadlock detection performs a cycle-detection search which is O(n) in the length of resource-dependency chains. Resource-dependency chains are bounded by the number of threads, the number of resources, and the number of allocations.

 

 

 

  1. Detect deadlock and roll back thread's actions

     

This algorithm performs the same runtime check discussed previously but also entails a logging cost which is O(n) in the total number of memory writes performed.

 

 

 

  1. Restart thread and release all resources if thread needs to wait This algorithm is grossly inefficient for two reasons. First, because threads run the risk of restarting, they have a low probability of completing. Second, they are competing with other restarting threads for finite execution time, so the entire system advances towards completion slowly if at all.

     

 

This ordering does not change when deadlock is more likely. The algorithms in the first group incur no additional runtime penalty because they statically disallow deadlock-producing execution. The second group incurs a minimal, bounded penalty when deadlock occurs. The algorithm in the third tier incurs the unrolling cost, which is O(n) in the number of memory writes performed between checkpoints. The status of the final algorithm is questionable because the algorithm does not allow deadlock to occur; it might be the case that unrolling becomes more expensive, but the behavior of this restart algorithm is so variable that accurate comparative analysis is nearly impossible.


Restart thread and release all resources if thread needs to wait This algorithm is grossly inefficient for two reasons. First, because threads run the risk of restarting, they have a low probability of completing. Second, they are competing with other restarting threads for finite execution time, so the entire system advances towards completion slowly if at all.

Related Solutions

conditions of deadlock
Show that the four conditions of deadlock apply to Figure.
deadlock avoidance
What is the difference among deadlock avoidance, detection, and prevention?
1. Try running the deadlock simulator using the following command: java deadlock a 2 2 Explain...
1. Try running the deadlock simulator using the following command: java deadlock a 2 2 Explain why a deadlock does not occur. 2. There are two additional process command files ("b0.dat" and "b1.dat") in the distribution. Run the deadlock simulator with this command: java deadlock b 2 1 1 What happens? Now try this: java deadlock b 2 1 2 Why does the first command result in a deadlock but the second does not? Explain your answer in terms of...
Write a program to detect the deadlock occurrence and write the sequence if there is a...
Write a program to detect the deadlock occurrence and write the sequence if there is a safe state. Noted: C or C++
There are four conditions that must hold simultaneously in a computer system for a deadlock to...
There are four conditions that must hold simultaneously in a computer system for a deadlock to occur. Name each condition and explain what it means.
Which of these statements about deadlock are true? (list all that are true.) a. If all...
Which of these statements about deadlock are true? (list all that are true.) a. If all transactions use two-phase locking, they cannot deadlock. b. Once two transactions deadlock, one of them must be aborted to maintain correctness. c. Systems that support update locks (S, X and U modes) cannot deadlock. d. Validation based concurrency control schemes cannot deadlock.
What is a deadlock in SQL Server transaction processing? Are they preventable, if so how?
What is a deadlock in SQL Server transaction processing? Are they preventable, if so how?
What data processing models would you prescribe for each of the following: handling airline reservations, handling...
What data processing models would you prescribe for each of the following: handling airline reservations, handling total sales by department for each day of operations, and measuring the quality of cookies coming off an assembly line?
Case: Disability Insurance Claims Handling at InsureIT We consider the following business process for handling insurance...
Case: Disability Insurance Claims Handling at InsureIT We consider the following business process for handling insurance claims for disability insurance1 at an insurance company InsureIT. The process starts when a customer lodges a disability claim. To do so, the customer fills in a form including a 2 -page questionnaire describing the disability. The customer can submit the form physically at one of the branches of InsureIT, by postal mail, fax or simply via e-mail (digitally-signed document). When a claim is...
In terms of resources, what is the difference between deadlock and starvation? max 200 words
In terms of resources, what is the difference between deadlock and starvation? max 200 words
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT