Introduction
A concurrency-control protocol decides, operation by operation, whether a transaction may proceed, must wait, or must abort, so that every schedule it lets through is serializable. Locking is the most widely used approach: a transaction must hold a lock on an item before accessing it, and incompatible locks make other transactions wait. Locks alone do not guarantee serializability; the two-phase locking (2PL) rule about when locks are released does.
The questions to answer are whether a lock sequence obeys 2PL or strict 2PL, whether a schedule could have been produced by 2PL, what 2PL guarantees (serializability) and what it does not (freedom from deadlock and from cascading aborts).
Prerequisites
- Schedules, Conflict Serializability and View Serializability: conflicts, precedence graphs, equivalent serial orders.
Core concepts
Lock modes.
- Shared (S) lock on : needed to read . Several transactions may hold S locks on the same item.
- Exclusive (X) lock on : needed to write (and read) . No other transaction may hold any lock on .
A request is granted only if it is compatible with every lock other transactions hold on the item; otherwise the requester waits.

Notation: and request locks, releases one.
Two-phase locking (2PL). Each transaction has a growing phase, in which it may acquire locks but not release any, followed by a shrinking phase, in which it may release locks but not acquire any. The moment it acquires its last lock is its lock point. Upgrading S to X is allowed only in the growing phase, downgrading X to S only in the shrinking phase.
Variants.
- Basic 2PL: the rule above. Guarantees conflict serializability.
- Strict 2PL: additionally holds every X lock until commit or abort. Schedules are conflict serializable and strict, so there are no cascading aborts.
- Rigorous 2PL: holds all locks until commit or abort. Transactions serialize in commit order.
- Conservative (static) 2PL: acquires all locks before the first operation (it must predeclare its read and write sets). It never deadlocks, because a transaction never waits while holding a lock.

How it works
Why 2PL gives conflict serializability. If is an edge of the precedence graph, some item was locked incompatibly by first and released by before could lock it. released a lock, so it had passed its lock point; then acquired one, so its lock point comes later. Every edge goes from an earlier lock point to a later one, so the graph is acyclic and the lock-point order is an equivalent serial order.
Deadlock. 2PL does not prevent deadlock: holds and requests while holds and requests . Systems handle it by:
- detection: a wait-for graph with an edge when waits for a lock held by ; a cycle means deadlock, and a victim is rolled back;
- prevention: conservative 2PL, ordering the items and locking in that order, or timestamp schemes such as wait-die and wound-wait (see Timestamp-Based Concurrency Control);
- timeouts: abort a transaction that waits too long.
Starvation is a separate risk: a transaction can wait forever if the lock manager keeps granting S locks to newcomers while it waits for X, or if it is always chosen as the deadlock victim. Fair (FIFO) granting and counting how often a transaction has been a victim prevent it.
Mathematical explanation
2PL produces a strict subset of CSR. Every 2PL schedule is conflict serializable, but not every conflict-serializable schedule can be produced by 2PL, because 2PL also fixes the serial order to the lock-point order and forbids a transaction from releasing one lock before acquiring another.
Testing whether a schedule could come from 2PL. Choose a lock point for each transaction; then each lock is held over the shortest interval allowed: from the earlier of its first use and the lock point, to the later of its last use and the lock point (for strict 2PL, X locks to the commit). Check interval compatibility per lock mode: S-to-X upgrades occur in the growing phase and X-to-S downgrades in the shrinking phase. A later write does not make the entire item interval X-locked. The schedule is 2PL-producible only when a compatible phase-respecting mode schedule exists; use mode-specific intervals, not one blanket X interval for an eventually written item.
Cascading aborts under basic 2PL. A transaction may release an X lock after its lock point but before commit; another transaction can then read the uncommitted value. Strict 2PL closes exactly this gap, which is why it is the variant used in practice.
Worked examples
Example 1: a 2PL transaction (Figure 2). reads and moves an amount from to :
Locks held rise ; the lock point is ; then . This is 2PL but not strict: releases an X lock before . The strict version keeps where it is and moves both and after . Releasing right after , before , would break 2PL.
Example 2: locking without 2PL is not enough. : ; : . The lock table allows to run entirely between and , giving : edges on and on , a cycle. is not two-phase (it acquires after releasing ).
Example 3: CSR but not producible by 2PL. . Edges and : conflict serializable, equivalent to . Under 2PL, must release its lock on before (second operation) but cannot hold its X lock on before (third operation), so it would acquire after releasing. No 2PL execution produces .
Example 4: basic but not strict 2PL. is producible by basic 2PL ( unlocks after ) but not by strict 2PL, which keeps until and so blocks . Moving before gives a schedule strict 2PL allows.
Example 5: deadlock. : , then requests ; : , then requests . Wait-for graph: and , a cycle. Both obey 2PL. Conservative 2PL (lock both items before starting) or locking items in a fixed order ( before ) would prevent it.
Example 6: shared locks allow concurrency. and both execute . Both locks are granted at once. If then requests , it waits until both release.
Example 7: strict but not rigorous. . Precedence: only, so is CSR, equivalent to , although commits first. Strict 2PL can produce it:
reaches its lock point when it gets , then releases its shared lock on , which strict 2PL permits; its X lock on is held to . Rigorous 2PL cannot produce : would hold until , so could not run before . This matches the rule that rigorous 2PL serializes in commit order, and here the serial order is the reverse of the commit order.
Example 8: one table for the three variants. Can the schedule be produced?
| Schedule | Basic 2PL | Strict 2PL | Rigorous 2PL |
|---|---|---|---|
| (Example 4) | yes | no | no |
| (Example 7) | yes | yes | no |
| yes | yes | yes | |
| (Example 3) | no | no | no |
In the third row both shared locks coexist and upgrades to an X lock on after . The last row is conflict serializable, which shows again that CSR does not imply producible by 2PL.
Important properties and observations
- S is compatible only with S; X is compatible with nothing.
- 2PL guarantees conflict serializability; the lock-point order is a serial order.
- 2PL allows deadlock and, in the basic form, cascading aborts.
- Strict 2PL gives strict, conflict-serializable schedules; rigorous 2PL serializes in commit order.
- Conservative 2PL is deadlock-free but needs read and write sets in advance.
- Not every CSR schedule is a 2PL schedule (Example 3).
- Deadlock is a cycle in the wait-for graph.
Common misconceptions.
- "2PL prevents deadlock." Only the conservative variant does.
- "2PL means locks are released only at commit." That is strict or rigorous 2PL.
- "Any CSR schedule can be produced by 2PL." Example 3 is a counterexample.
- "Strict 2PL holds shared locks to commit." Only X locks; holding all is rigorous 2PL.
GATE examination perspective
- Check a lock sequence. Apply this to 2PL, strict 2PL or rigorous 2PL.
- Decide. Determine whether a schedule can be produced by 2PL or strict 2PL.
- Properties. Serializability, deadlock freedom, cascadeless behaviour of each variant.
- Deadlock. Draw the wait-for graph and find the cycle.
- Compatibility. Which requests are granted given the current locks.
Summary
Sources
- A. Silberschatz, H. F. Korth, S. Sudarshan, Database System Concepts, 7th ed., McGraw-Hill, 2019 (2020 copyright), 18.1 Lock-Based Protocols, 18.2 Deadlock Handling.
- R. Elmasri, S. B. Navathe, Fundamentals of Database Systems, 7th ed., Pearson, 21.1 Two-Phase Locking Techniques for Concurrency Control.