In computer science, strict two-phase locking (Strict 2PL) is a lockinging method used in database management systems.
The two rules of Strict 2PL are:
- If a transaction T wants to read/write an object, it must request a shared/exclusive lock on the object.
- All locks held by transaction T are released when T commits (and not before).
T1: S(A), R(A); T2: S(A), R(A), X(B), R(B), W(B), Commit; T1: X(C), R(C), W(C), Commit
where
- S() is a shared lock action on an object
- X() is an exclusive lock action on an object
- R() is a read action on an object
- W() is a write action on an object
A deadlocked schedule supposedly allowed in Strict 2PL:
T1 is waiting for T2's lock on B to be released, while T2 is waiting for T1's lock on A to be released. These transactions cannot proceed and is deadlocked.
If an user wishes to guarantee that no deadlocks occur, 2PL would be one option. Assigning Timestamps would be another.