What do you mean by deadlock?

Answer Posted / sreenath kambly n

A set of processes is deadlocked if each process in the set
is waiting for an event that only another process in the
set can cause (including itself).

Waiting for an event could be:

waiting for access to a critical section
waiting for a resource Note that it is usually a non-
preemptable (resource). pre-emptable resources can be
yanked away and given to another.
Conditions for Deadlock

Mutual exclusion: resources cannot be shared.
Hold and wait: processes request resources incrementally,
and hold on to what they've got.
No preemption: resources cannot be forcibly taken from
processes.
Circular wait: circular chain of waiting, in which each
process is waiting for a resource held by the next process
in the chain.
Strategies for dealing with Deadlock

ignore the problem altogether ie. ostrich algorithm it may
occur very infrequently, cost of detection/prevention etc
may not be worth it.
detection and recovery
avoidance by careful resource allocation
prevention by structurally negating one of the four
necessary conditions.
Deadlock Prevention

Difference from avoidance is that here, the system itself
is build in such a way that there are no deadlocks.

Make sure atleast one of the 4 deadlock conditions is never
satisfied.

This may however be even more conservative than deadlock
avoidance strategy.

Attacking Mutex condition
never grant exclusive access. but this may not be possible
for several resources.
Attacking preemption
not something you want to do.
Attacking hold and wait condition
make a process hold at the most 1 resource at a time.
make all the requests at the beginning. All or nothing
policy. If you feel, retry. eg. 2-phase locking
Attacking circular wait
Order all the resources.
Make sure that the requests are issued in the correct order
so that there are no cycles present in the resource graph.

Resources numbered 1 ... n. Resources can be requested only
in increasing order. ie. you cannot request a resource
whose no is less than any you may be holding.
Deadlock Avoidance

Avoid actions that may lead to a deadlock.

Think of it as a state machine moving from 1 state to
another as each instruction is executed.

Safe State
Safe state is one where

It is not a deadlocked state
There is some sequence by which all requests can be
satisfied.
To avoid deadlocks, we try to make only those transitions
that will take you from one safe state to another. We avoid
transitions to unsafe state (a state that is not
deadlocked, and is not safe)

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category