Deadlock Prevention
Deadlock Prevention
Deadlock Prevention
Section B
Question 5.Answer
Deadlock: Deadlock is an unwanted situation that arises in a shared resource
environment, where a process indefinitely waits for a resource that is held by another
process.
For example, assume a set of transactions {T , T , T , ...,T }. T needs a resource X to
0 1 2 n 0
complete its task. Resource X is held by T , and T is waiting for a resource Y, which is
1 1
held by T . T is waiting for resource Z, which is held by T . Thus, all the processes wait
2 2 0
for each other to release resources. In this situation, none of the processes can finish
their task. This situation is known as a deadlock.
Prevention:
To prevent any deadlock situation in the system, the DBMS aggressively inspects all the
operations, where transactions are about to execute. The DBMS inspects the
operations and analyzes if they can create a deadlock situation. If it finds that a
deadlock situation might occur, then that transaction is never allowed to be executed.
There are deadlock prevention schemes that use timestamp ordering mechanism of
transactions in order to predetermine a deadlock situation . These are deadlocks :
Wait-Die Scheme
In this protocol, if a transaction requests to lock a resource (data item), which is already
held with a conflicting lock by another transaction, then one of the two possibilities may
occur −
• If TS(T ) < TS(T ) − that is T , which is requesting a conflicting lock, is older than
i j i
• If TS(T ) > TS(t ) − that is T is younger than T − then T dies. T is restarted later
i j i j i i
Wound-Wait Scheme
In this protocol, if a transaction requests to lock a resource (data item), which is already
held with conflicting lock by some another transaction, one of the two possibilities may
occur −
• If TS(T ) < TS(T ), then T forces T to be rolled back − that is T wounds T . T is
i j i j i j j
restarted later with a random delay but with the same timestamp.
• If TS(T ) > TS(T ), then T is forced to wait until the resource is available.
i j i
This protocol, allows the younger transaction to wait; but when an older transaction
requests an item held by a younger one, the older transaction forces the younger one to
abort and release the item.