Two-Phase Locking (2PL) Protocol: Short Notes for Concurrency Control

Two-Phase Locking (2PL) Protocol: Short Notes for Concurrency Control

Verified Sources
Sep 12, 2026

Two-Phase Locking (2PL) is a locking-based concurrency control protocol used to ensure that interleavings of transactions remain conflict-serializable. The core idea is that each transaction follows a strict two-stage discipline for acquiring and releasing locks: it first grows its set of locks, and only then shrinks by releasing locks. In particular:

During the growing phase, a transaction may acquire (shared/exclusive) locks, but it must not release any held lock. Once it enters the shrinking phase, it may release locks, but it must not acquire any new locks. This separation prevents “lock conversion/release-then-reacquire” patterns that can otherwise produce schedules that are not conflict-serializable.

Key terms:

  • Two-Phase Locking
  • Growing phase
  • Shrinking phase
  • Shared lock (S-lock)
  • Exclusive lock (X-lock)

Limitation note: I’m unable to perform the required web searches right now due to a tool usage limitation (external sources/citations are unavailable). The content below is based on standard database concurrency-control theory.

Two-Phase Locking (2PL) - Growing and Shrinking Phases (Conceptual)

Locking compatibility and why 2PL works

2PL relies on the compatibility rules of lock types:

  • S-locks are compatible with S-locks (multiple readers allowed).
  • X-locks are incompatible with S-locks and X-locks (writers require exclusive access).

Let’s model the state of a transaction TiT_i as the set of locks it holds over time. The 2PL discipline enforces that:

  • every lock acquisition for TiT_i occurs before its first lock release,
  • after the first release, TiT_i cannot acquire new locks.

This ordering property is what supports the proof that 2PL schedules are conflict-serializable: intuitively, it prevents cycles in the precedence (conflict) graph that arise when transactions alternate between acquiring and releasing locks.

Mermaid view of the “no switching back” rule:

How a Transaction Follows 2PL

  1. 1
    Step 1

    As TiT_i executes, it requests S-locks for reads and X-locks for writes. It cannot release any lock yet.

  2. 2
    Step 2

    Once TiT_i releases any lock, it permanently transitions to shrinking.

  3. 3
    Step 3

    After entering shrinking, TiT_i may release locks but must not request any additional locks.

  4. 4
    Step 4

    At the end, remaining locks are released by transaction completion (consistent with the shrinking rule).

Minimal and common variations: Strict 2PL (rigorous timing)

A widely used strengthening is Strict 2PL (also called rigorous 2PL). The key rule is:

  • A transaction holds all X-locks until it commits or aborts (i.e., it cannot release write locks early).

This design prevents cascading aborts, because no other transaction can read uncommitted (dirty) data written by a transaction that later aborts.

Key terms:

  • Strict 2PL
  • Cascading abort
  • Dirty read
  • Recoverability

Callout intuition: strict 2PL is more conservative (can reduce concurrency) but is very safe for recovery.

Pro Tip

When writing short notes for exams, always mention: (1) growing vs shrinking phases, (2) “no lock acquisition after first unlock,” and (3) optional upgrade to strict 2PL to prevent cascading aborts.

Common Pitfall

Don’t confuse 2PL with mere “lock correctness.” The two-phase constraint (acquire then release only) is what guarantees conflict-serializability; releasing early without a shrinking phase can break the guarantee.

2PL Transaction Timeline

Growing

Phase 1

Acquire locks (S for read, X for write). No releasing."

First lock release

Boundary

Transaction enters shrinking phase here."

Shrinking

Phase 2

Release locks. No further lock acquisitions."

Commit/Abort

End

Final completion; locks are released (consistent with shrinking)."

Quick Exam-Ready Notes

Effect of 2PL Variants on Concurrency vs Safety

Higher safety usually reduces concurrency due to stricter lock holding.

Knowledge Check

Question 1 of 4
Q1Single choice

In Two-Phase Locking (2PL), what is the key restriction after a transaction releases its first lock?

Explore Related Topics

1

Understanding Digital Counters: Principles, Types, and Applications

Digital counters are sequential circuits built from cascaded flip‑flops that count input events, with a maximum modulus of 2ᴺ for N stages, and are classified as asynchronous (ripple) or synchronous based on clock distribution.

  • Asynchronous counters cascade flip‑flop clocks, causing cumulative propagation delay and limiting maximum frequency.
  • Synchronous counters receive the clock simultaneously, using combinational logic to eliminate ripple delay and support higher speeds.
  • Designing a synchronous Mod‑6 counter involves defining the state sequence, creating excitation tables, simplifying with Karnaugh maps, and wiring JK flip‑flops with derived logic.
  • Ring counters yield N states; Johnson counters double this to 2N states.
  • Prevent glitches and lock‑out by using Gray‑code sequencing, output strobes, and ensuring unused states redirect to the main count sequence.
2

Reader–Writer Problem and Semaphore-Based Process Synchronization

3

Deadlock Prevention by Breaking Coffman Conditions

Deadlock can be avoided by breaking any one of the four Coffman conditions through system‑level policies.

  • Mutual exclusion: Make resources sharable where feasible (e.g., spooling), though many devices are inherently exclusive.
  • Hold and wait: Require a process to request all needed resources before it starts, eliminating partial holding.
  • No preemption: Allow the OS to force a process to release its current resources when a new request cannot be satisfied.
  • Circular wait: Impose a total order R1<R2<<RnR_1 < R_2 < \dots < R_n on resource types and permit requests only in increasing order, preventing cycles such as P1P2P3P1P_1 \to P_2 \to P_3 \to P_1.