IAE Academy

GATE 2024 CS2 Q.27: solution and answer

GATE 2024 · CS2Q.27 · 1 mark · MSQ

Which of the following statements about the Two Phase Locking (2PL) protocol is/are TRUE?

  1. (A)

    2PL permits only serializable schedules

  2. (B)

    With 2PL, a transaction always locks the data item being read or written just before every operation and always releases the lock just after the operation

  3. (C)

    With 2PL, once a lock is released on any data item inside a transaction, no more locks on any data item can be obtained inside that transaction

  4. (D)

    A deadlock is possible with 2PL

See the question in the paper

Answer and solution

ANSWER

The true statements are (A), (C) and (D).

Official answer: A, C, DSource: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. Recall the rule: in Two Phase Locking every transaction has a growing phase (it only acquires locks) followed by a shrinking phase (it only releases locks). The first unlock marks the lock point, and no lock may be acquired after it.

  2. (A) Every schedule allowed by 2PL is conflict serializable, because the transactions can be ordered by their lock points. So 2PL permits only serializable schedules. TRUE.

  3. (B) Locking an item just before each operation and releasing it just after means the transaction unlocks one item and then locks the next. That is an unlock followed by a lock, which breaks the two-phase rule. Basic 2PL does not require per-operation locking and releasing, and a transaction that did this would not be following 2PL. FALSE.

  4. (C) This is the definition of 2PL: once any lock has been released (the shrinking phase has begun), no new lock on any data item can be obtained by that transaction. TRUE.

  5. (D) 2PL does not prevent deadlock. For example, holds an exclusive lock on and requests one on , while holds an exclusive lock on and requests one on . Both are in their growing phase and wait for each other forever. TRUE.

  6. The true statements are A, C and D.

KEY IDEA

Two Phase Locking means no lock is acquired after the first unlock. This guarantees conflict serializability, but it does not prevent deadlock.

WATCH OUT FOR

Thinking that 2PL is deadlock-free because it is serializable. Deadlock freedom is a separate property, so 2PL needs deadlock detection or prevention on top. Another slip is taking per-operation lock and release (B) as 2PL, when it is the opposite of two-phase behaviour.

From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 9 Transactions questions, with notes

More Transactions questions