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.
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
Implement the Banker's algorithm for deadlock avoidance, that works on a given set of N processes...
Implement the Banker's algorithm for deadlock avoidance, that works on a given set of N processes and M resource types (N<10,M<10). Use C/C++/C# or Java for the implementation, with a simple text interface, where the user enters only the name of the input file (text only). The program reads all the necessary input data from that file. The input data and result is then displayed on the screen. You may use your program to validate the example you gave in...
Which of the following is true? Select one: a. No deadlock implies no starvation; b. Starvation...
Which of the following is true? Select one: a. No deadlock implies no starvation; b. Starvation implies deadlock. c. No starvation implies no deadlock; d. Deadlock doesn’t imply starvation; Which of the following indicates that Pi can enter the critical section in Peterson’s solution? Select one: a. flag[j] == true or turn == i b. flag[j] == true and turn == j c. flag[j] == false or turn == j d. flag[j] == false or turn == i Assume the...
Consider the bankers algorithm for deadlock avoidance. Give an example of this algorithm for 7 processes...
Consider the bankers algorithm for deadlock avoidance. Give an example of this algorithm for 7 processes and 5 resource types.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT