Lock-Based Protocols and Basic 2PL Explained: Lock Compatibility, Phases and a Worked Schedule

Learn to test a concrete schedule for Basic 2PL by tracing S and X locks, lock points, waits, unlocks, values, and the resulting precedence graph.

KnowledgeGate Team

Exam prep & CS education

Updated 30 Nov 20265 min read
Lock-Based Protocols and Basic 2PL Explained: Lock Compatibility, Phases and a Worked Schedule

Memorising that two-phase locking has two phases is easy. The harder task is deciding whether a concrete interleaved schedule actually obeys Basic 2PL. Use a fixed method: check lock compatibility, mark each transaction's lock point, inspect every unlock, and then derive the serial order. Basic 2PL guarantees conflict serializability, but it does not by itself guarantee deadlock freedom or strict execution.

Lock-based protocols in DBMS: what S and X locks permit

A shared lock S(A) gives permission to read item A. An exclusive lock X(A) gives permission to read and write A. Operationally, a read needs either S or X, while a write needs X.

Requested lock

Existing S

Existing X

S

Grant

Wait

X

Wait

Wait

Compatibility is checked per data item. A transaction holding X(A) does not block an unrelated lock request on B. Also distinguish a request from a grant: a waiting request is not yet a held lock, and an unlock releases a granted lock.

The wider Transactions and Concurrency Control in DBMS guide places these locks inside transaction schedules. The CS Fundamentals category provides the broader DBMS learning route.

Basic 2PL: growing phase, lock point and shrinking phase

During the growing phase, a transaction may acquire new locks or upgrade S to X. It may not release or downgrade any lock. Its lock point is the instant it obtains its final lock, not its first lock and not necessarily its commit.

The first unlock or downgrade starts the shrinking phase. From that instant, the transaction may release locks but may acquire no new one. This is legal:

X1(A), R1(A), W1(A), X1(B), R1(B), W1(B), U1(A), U1(B), C1

Here, X1(B) is T1's lock point and U1(A) begins shrinking. By contrast, S3(A), R3(A), U3(A), X3(B), W3(B) is illegal because T3 requests a new lock after its first unlock.

Basic 2PL worked example: follow every value and lock state

Let A = 100 and B = 50. T1 transfers 20 from A to B, and T2 reads B after T1.

Step

Operation

Lock state on A

Lock state on B

Result or wait

1

Grant X1(A)

X:T1

None

Granted

2

R1(A), W1(A)

X:T1

None

Read 100; write 100 - 20 = 80

3

Grant X1(B)

X:T1

X:T1

Granted; T1 lock point

4

R1(B), W1(B)

X:T1

X:T1

Read 50; write 50 + 20 = 70

5

Request S2(B)

X:T1

X:T1; S:T2 queued

Wait, S conflicts with X

6

U1(A)

None

X:T1; S:T2 queued

T1 enters shrinking phase

7

U1(B)

None

None; S:T2 queued

T1 releases B

8

C1

None

None; S:T2 queued

T1 commits

9

Grant S2(B), R2(B)

None

S:T2

T2 reads 70; T2 lock point

10

U2(B)

None

None

T2 enters shrinking phase

11

C2

None

None

T2 commits

T1 leaves A = 100 - 20 = 80 and B = 50 + 20 = 70. T2 observes 70, so the final values are A = 80 and B = 70. T1 obtains no lock after U1(A), and T2 obtains no lock after U2(B). Both therefore obey Basic 2PL.

Correct 11-step Basic 2PL timeline: T2 requests S2(B) after T1 writes B, waits, then reads 70.

Why Basic 2PL produces a conflict-serializable schedule

The only cross-transaction conflict in this schedule is W1(B = 70) before R2(B = 70). The precedence graph therefore has one edge, T1 -> T2. There is no edge back to T1, so the graph is acyclic and the conflict-equivalent serial order is T1 followed by T2.

The general reason comes from lock points. For a conflict edge Ti -> Tj, Ti must release its incompatible lock before Tj can obtain its lock. Under 2PL, Ti's lock point occurs before that release, while Tj's lock point occurs at or after its later acquisition. The lock points must therefore order Ti before Tj, so they cannot form a cycle.

This proves that schedules generated by 2PL are conflict serializable. It does not prove the converse: a conflict-serializable schedule need not have been generated by 2PL.

Precedence graph showing T1 before T2 and final values A = 80 and B = 70.

Basic 2PL limitations and the stricter variants

Basic 2PL can deadlock even while both transactions are growing. Suppose T4 gets X4(A) and T5 gets X5(B). T4 then requests X4(B) and waits, while T5 requests X5(A) and waits. Neither can proceed.

It can also permit cascading rollback. Start with X = 40. T6 gets X6(X), writes X = 55, and unlocks X before committing. T7 then gets S7(X) and reads 55. This obeys Basic 2PL, but if T6 aborts, T7 has consumed an uncommitted value and must also roll back.

Protocol

Lock rule

Main consequence

Basic 2PL

Grow, then shrink

Conflict serializability

Conservative 2PL

Obtain every required lock before execution

Avoids deadlock, with lower concurrency

Strict 2PL

Hold exclusive locks until commit or abort

Prevents reads or overwrites of uncommitted writes

Rigorous 2PL

Hold shared and exclusive locks until commit or abort

Stronger release discipline

Basic 2PL traps that turn correct-looking schedules into wrong answers

  1. Two phase does not mean two lock operations. It means every acquisition precedes that transaction's first release.

  2. Phases are per transaction. Different transactions can be growing or shrinking at the same point in the global schedule.

  3. Upgrades and downgrades count. An S to X upgrade is an acquisition and belongs in growing. It must wait if another transaction holds S on the item. An X to S downgrade is a release and begins shrinking.

  4. Do not confuse guarantees. Basic 2PL gives conflict serializability, not deadlock freedom, cascadelessness, or strictness.

Test S8(A), R8(A = 80), X8(B), W8(B = 75), U8(A), X8(C). It violates Basic 2PL because X8(C) follows the first unlock. Moving X8(C) before U8(A) is the minimum repair.

How GATE tests lock-based protocols and Basic 2PL

The GATE 2026 Computer Science syllabus published by IIT Guwahati includes transactions and concurrency control under DBMS.

Common reasoning formats are completing an S/X compatibility table, testing a lock sequence for 2PL, drawing a wait-for or precedence graph, and distinguishing Basic, conservative, strict, and rigorous 2PL. For immediate practice, use DBMS Transaction MCQs: 12 Solved (ACID, Locking).

Your 30-second checklist is: mark every grant and unlock per transaction, circle its first unlock, reject any later acquisition, resolve incompatible requests as waits, draw the conflict edges, and read the serial order.

Lock-based protocols and Basic 2PL: the short version and next step

Keep four lines in memory:

  • S + S is allowed.

  • Any pair involving X conflicts.

  • Growing means acquire but do not release.

  • Shrinking means release but do not acquire.

Lock-point order gives the conflict-equivalent serial order. If you need the wider subject sequence, CS Fundamentals for Placements by Sanchit Sir provides that route. If you already know the theory and need timed GATE application, use the GATE Test Series.

Now redraw the worked schedule from memory. Your version should end with A = 80, B = 70, show the waiting S2(B) request, and produce the edge T1 -> T2.