B-Pharmacy Colleges

Advantages of Two Phase Locking

 

 

Two-Phase Locking to Ensure Serializability:

Two-phase locking defines how transactions acquire and relinquish locks.

Two-phase locking guarantees serializability, but it does not prevent deadlocks. The two phases are:

 

1. A growing phase, in which a transaction acquires all required locks without unlocking any data. Once all locks have been acquired, the transaction is in its locked point.

 2. A shrinking phase, in which a transaction releases all locks and cannot obtain any new lock.

The two-phase locking protocol is governed by the following rules:

• Two transactions cannot have conflicting locks.

 • No unlock operation can precede a lock operation in the same transaction.

 • No data are affected until all locks are obtained—that is, until the transaction is in its locked point.

 

Two Phase Locking Protocols

The two-phase locking protocol

In this example, the transaction acquires all of the locks it needs until it reaches its locked point. (In this example, the transaction requires two locks.) When the locked point is reached, the data are modified to conform to the transaction’s requirements. Finally, the transaction is completed as it releases all of the locks it acquired in the first phase.

 


Two-phase locking increases the transaction processing cost and might cause additional undesirable effects. One undesirable effect is the possibility of creating deadlocks.

You May Also Like:

Transaction and Its Properties
Concurrency Problems
Deadlocks in DBMS
Types of Locks
Find More DBMS Questions