Two-phase locking

In databases and transaction processing, two-phase locking (2PL) is a pessimistic concurrency control method that guarantees conflict-serializability.

The serializability property is guaranteed for a schedule with transactions that obey this rule.

Furthermore, each transaction needs to declare its read and write set (the data items that will be read/written), which is not always possible.

To comply with the strict two-phase locking (S2PL) protocol, a transaction needs to comply with 2PL, and release its write (exclusive) locks only after the transaction has ended (i.e., either committed or aborted).

On the other hand, read (shared) locks are released regularly during the shrinking phase.