1
$\begingroup$

deadlock cycle

Suppose i have the following resource allocation graph with a deadlock cycle, i see why it is a deadlock cycle, what i don't get is how to recover from this cycle

i'm thinking about aborting a process, any process here will lead to non-deadlock situation, but doesn't that cause the other process to not execute and hence the program won't execute as we're expecting it to be, i think this is a correct answer, but is there another way to do such that all processes will eventually run ?

$\endgroup$
0
$\begingroup$

You don’t exit a deadlock cycle. Once you are in a deadlock situation, you lost. You do your best to avoid deadlocks.

With server software, you may be able to have a process that watches other processes and kills them if they are stuck due to a deadlock. Doing this correctly and make your software continue to run correctly is extremely difficult. It’s so difficult that i wouldn’t even try. In addition it is an absolute pain to test (and you don’t want software that isn’t tested). For normal software running in anything from workstation to mobile phone, it’s just not done. Remember that you have two tasks that are trying to do something and one or both of them have to be killed, that is hard to recover from.

What you do in practice: 1. Instead of locking a mutex you check if it is lockable which avoids deadlocks. 2. You add code that detects situations where a deadlock is possible. And if you find a possible deadlock you fix your code. 3. Write sensible code in the first place.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Note: breaking free of the deadlock isn't that hard, but it comes with a price: you may violate things that are otherwise invariant. This can be a big deal in many applications. For example, some of the classic banking applications can execute half of a transfer, crediting one account but failing to debt the other, or vice versa. Proving that this sort of behavior is acceptable is what is so difficult to do right. $\endgroup$ – Cort Ammon Jul 4 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.