Q4.Marks: +2.0UGC NET Paper 2: Computer Science17th June 2023
Given below are two statements:
Which of the following concurrency control protocol ensures both conflict serializability and freedom from deadlock?
Statement I: Two phase locking
Statement II: Timestamp ordering
In the light of the above statements, choose the most appropriate answer from the options given below:
1.Both Statement I and Statement II are correct
2.Both Statement I and Statement II are incorrect
3.Statement I is correct but Statement II is incorrect
4.Statement I is incorrect but Statement II is correct✓ Correct
Solution
The correct answer is Statement I is incorrect but Statement II is correct
Key Points
Two-phase locking (2PL):
In this protocol, each transaction goes through two phases:
The expanding (or growing) phase where locks are acquired, and the shrinking phase where locks are released.
The name "two-phase" comes from the fact that all lock acquisitions occur before any lock is released.
This ensures a level of consistency and conflict serializability, as two conflicting transactions can't be running at the same time.
However, this method doesn't guarantee a deadlock-free environment.
A deadlock situation can occur when two (or more) transactions each hold a resource the other needs, creating a standoff where neither can proceed.
Timestamp-based protocol:
In timestamp-based protocols, each transaction is assigned a unique timestamp at the moment it is created.
There are two types of timestamp protocols:
Thomas Write Rule and Basic Timestamp Ordering. The one that provides both conflict serializability and freedom from deadlock is the Basic Timestamp Ordering.
This protocol ensures each transaction respects the chronological (timestamp) order of other transactions. When conflicts arise (for example if a later (younger) transaction tries to write data that an earlier (older) transaction is reading or writing), the conflicting transaction can be rolled back and restarted to prevent the scenario from causing inconsistency, thus ensuring conflict serializability.
And since a younger transaction will always concede to an older one by being rolled back and restarted, there's no chance for deadlocks to occur, thus ensuring freedom from deadlock.
So, Statement I is incorrect because Two-phase locking (2PL) does not ensure freedom from deadlock, and Statement II is correct because Timestamp-based protocol ensures both conflict serializability and freedom from deadlock.