1. Two-phase Locking
- T want to R/W on X-->Get the lock on X first!
- issue lock and unlock requests in 2 phases
a. Growing Phase: only lock; no unlock
b. Shrinking Phase: only unlock; no lock
- once Ti releases a lock, it can never request lock.
- 2PL allows only conflict-serializable schedules;
- Not all conflict-serializable schedules are allowed by 2PL
e.g.:
(1)
transactions with lock-unlock sequence conforming 2PL protocol
T1: Slock(A),Xlock(B),SLock(C) Unlock(B),Unlock(C),Unlock(A) Commit
T2: Slock(A), Xlock(B)Wait.................Xlock(B) Unlock(A),Unlock(B) Commit
transactions violating 2PL protocol:
T1: Slock(A),Slock(B),Unlock(A) Xlock(A) Unlcok(A) Unlock(B)
T2: Xlock(C),Xlock(D),Unlock(D),Slock(B),Unlock(C),Xlock(D),Unlock(D),Unlock(B)
(2)
A schedule generated by 2PL:
T1:R(A),R(B),R(C) W(C),
T2: R(A),R(B), W(A)
The corresponding lock-unlock sequence
T1:Slock(A),Slock(B),Slock(C) Xlock(C),Unlock(A)
T2: Slock(A),Slock(B) Xlock(A), Unlock(A),Unlock(B),
Question: Is it allowed?
Can T2 Xlock on A before it releases the slock on A locked by itself???