Question
In a database system, unique timestamps are assigned to each transaction using Lamport's logical clock. Let and be the timestamps of transactions and respectively. Besides, holds a lock on the resource , and has requested a conflicting lock on the same resource . 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(T1) < TS(T2) then
T1 is killed
else
T1 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?
Official answer and solution
- Official answer
- A
- From
- Official GATE 2017 answer key
Solution
Analyze the wait-for relationships and transaction restart mechanism under the given timestamp-based deadlock prevention algorithm.
The deadlock prevention algorithm specifies:
When transaction requests a lock held by :
- If (i.e., is older than ), is killed.
- If (i.e., is younger than ), waits.
- Deadlock Freedom:
In this scheme, a transaction waits only if it is younger than the transaction holding the lock (). Consequently, in the wait-for graph, all directed edges point from younger transactions to strictly older transactions. Because timestamps form a strict total order and strictly decrease along every path of waiting transactions, a directed cycle can never form in the wait-for graph. Therefore, the system is guaranteed to be deadlock-free.
- Starvation Freedom:
When a transaction is killed, it is restarted with its original timestamp . As new transactions enter the system, they receive newer (larger) timestamps. Eventually, 's timestamp becomes smaller than that of other active transactions. An older transaction holding resources is never killed by younger transactions (younger transactions wait for it), so can acquire needed resources and proceed to completion without being indefinitely postponed. Therefore, the system is starvation-free.
Thus, the database system is both deadlock-free and starvation-free.
A
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 42 of 65, printed as CS Q.42
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.