GATE 2017 CS – Question 52
In a database system, unique timestamps are assigned to each transaction using Lamport's logical clock. Let $TS(T_1)$ and $TS(T_2)$ be the timestamps of transactions $T_1$ and $T_2$ respectively. Besides, $T_1$ holds a lock on the resource R, and $T_2$ has requested a conflicting lock on the same resource R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp.
if TS(T2) < TS(T1) then
T1 is killed
else T2 waits.Assume any transaction that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) The database system is both deadlock-free and starvation-free.
Explanation
When the requester is older (smaller timestamp), it kills the younger lock holder, and otherwise it waits. This is the wound-wait scheme. Transactions only ever wait for older ones, so there are no cycles and no deadlock. A killed transaction is restarted with the same timestamp, so it eventually becomes the oldest and cannot be killed again, which prevents starvation.