img
Question:
Published on: 22 December, 2024

Explain two-phase locking protocol.

Answer:

 

In a multiprogramming environment where multiple transactions can be executed simultaneously, it is highly important to control the concurrency of transactions. We have concurrency control protocols to ensure atomicity, isolation, and serializability of concurrent transactions. 

Two Phase Locking Protocol has two phases.

  1. Growing Phase: - transaction obtains locks but not releasing any locks.
  2. Shrinking Phase: - transaction releases locks and cannot obtain any new locks.

Initially the transaction is in growing phase, that is the transaction acquires locks as needed. Once the transaction releases lock, it enters the shrinking phase and no more lock request may be issued. Upgrading of lock is not possible in shrinking phase, but it is possible in growing phase. The two phase locking protocol ensures serializability.

Conservative 2PL (Two Phase Locking)

In conservative 2PL there is no growing Phase, Only having shrinking Phase. It gets all the locks before the execution starts.

Strict 2PL

Not releasing the write lock (Exclusive Lock) until commit.

 

 

Random questions