The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+3 votes
Q 1)  The query which is coming in my mind is which of the below techniques requires apriori information regarding the potential use , request of resources ?

a) Deadlock prevention

b) Deadlock avoidance

c) Deadlock detection

Q 2) Also what is the order of restrictiveness of the above techniques regarding the allocation of resources ?

Q 3) Is deadlock detection technique meant for before the deadlock has occured or after the deadlock has occured ?
asked in Operating System by Veteran (100k points) | 177 views

1 Answer

+3 votes
Best answer

Deadlock Prevention: The goal is to ensure that at least one of the 4 necessary conditions for deadlock never hold. The system does not require additional apriori information regarding the overall potential use of each resource for each process. This is difficult to implement in practice.

Deadlock Avoidance: The goal is to plan very carefully so that the system will not enter an unsafe state. In order for the system to decide whether the next state will be safe or unsafe, it must know in advance, at any time the additional apriori information regarding the overall potential use of each resource for each process.

Deadlock Detection: The goal is to find a deadlock before or after it has happened. Detecting the possibility of a deadlock before it occurs is more difficult. The system does not requires additional apriori information regarding the overall potential use of each resource for each process in all cases.

Therefore, the answer to your first question is (b) Deadlock Avoidance.

Answer to the second question: For deadlock detection, the resource allocation strategy is very liberal. That means, resources are granted as and when requested. For deadlock prevention, the resource allocation is very strict or   rather conservative. It generally under utilizes the resources. The resource allocation strategy for deadlock avoidance is not that liberal, it checks whether a safe sequence exists before allocating (very similar to the process of a banker checking its financial position before passing a loan). At the same time, it is not that conservative as in deadlock prevention.

Answer to the third question is that Deadlock Detection can be used to detect a deadlock before or after it has happened.

I think this explanation clarifies all three questions.

answered by Loyal (4.5k points)
selected by
Thanks a lot @visakh r..
How Deadlock detection can be used to detect a deadlock before it has happened ?

@visakh ,

Deadlock Detection can be used to detect a deadlock before or after it has happened.

Is it ?

I think In this technique, system does not prevent to attempt deadlocks from occuring .Instead it lets them occur , tries to detect when this happens and then takes some action to recover after the fact .

What action it takes to detect a deadlock ? Its wait for graph


Deadlock can be detected by examining which processes are waiting for which resources. For example, two processes A and B may attempt to acquire the following locks before executing a critical section:

Thread A: x, y, z

Thread B: z, a, b, c, x

Deadlock is possible if A tries to acquire lock z after B has already acquired z. Process A will continue to try to acquire z, holding on to x and y. Eventually, B will try to acquire x and deadlock is reached. Each process tries to acquire a lock held by another process.

When only one instance of each resource type is available, a variant of resource allocation graph called wait-for-graph is used to represent the processes. Deadlock detection algorithms work by creating a finite state model that has a set of states and  transitions. All the paths in the WFG are periodically run through the finite state model and checked for cycle forming possibility. If there is a chance for cycle in WFG, then deadlock is almost imminent.

For more details regarding finite model based deadlock detection, please go throuh this paper:

Even I think same

Under the deadlock detection, deadlocks are allowed to occur. Then the state of the system is examined to detect that a deadlock has occurred and subsequently it is corrected and recovered
yes deadlock prevention says just break all conditions so that deadlock cant even think of happening...deadlock avoidance says we should take all safety measures to ensure deadlock shouldnt happen like safe state concept...and deadlock detection is deadlock detection and "recovery" means let deadlock happen if it wants so we will see what to do then like peempt the resources,rollback,kill the process etc....and  detection also provides waits for graph as mentioned  above to detect it before happening also..

Related questions

+1 vote
0 answers
0 votes
0 answers
asked Dec 20, 2017 in Operating System by junaid ahmad Veteran (12.6k points) | 44 views
0 votes
0 answers

34,291 questions
41,038 answers
39,940 users