- Strict two-phase locking
In
computer science , strict two-phase locking (Strict 2PL) is a locking method used in concurrent 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).Here is an example of Strict 2PL in action with interleaved actions.
:D = egin{bmatrix}T1 & T2 \S(A) & \R(A) & \ & S(A) \ & R(A) \ & X(B) \ & R(B) \ & W(B) \ & Commit \X(C) & \R(C) & \W(C) & \Commit &end{bmatrix}
or in text form:
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(O) is a shared lock action on an object O
*X(O) is an exclusive lock action on an object O
*R(O) is a read action on an object O
*W(O) is a write action on an object OStrict 2PL prevents transactions
reading uncommitted data ,overwriting uncommitted data , andunrepeatable reads . Thus, it prevents cascading rollbacks, since eXclusive locks (for write privileges) must be held until a transaction commits.Strict 2PL does not guarantee a deadlock-free schedule
Avoiding deadlocks can be important in
real time systems, and may additionally be difficult to enforce indistributed data base s, orfault tolerant systems with multiple redundancy.A deadlocked schedule allowed under Strict 2PL:
:G = egin{bmatrix}T1 & T2\X(A) & \ & X(B) & \X(B) & \ & X(A) end{bmatrix}
Text:T1: X(A) T2:X(B) T1:X(B) T2: X(A)
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 both are deadlocked.
There is no general solution to the problem of
deadlock s in computing systems, so they must be anticipated and dealt with accordingly. Nonetheless, several solutions such as theBanker's algorithm or the imposition of a partial ordering on lock acquisition exist for avoiding deadlocks under certain conditions.Even more strict than strict two-phase locking is
rigorous two-phase locking , in which transactions can be serialized by the order in which they commit. Under rigorous 2PL, all locks (shared and exclusive) must be held until a transaction commits. Most database systems use strict 2PL.Non-strict two-phase locking
In
computer science , non-strict two-phase locking, also 2PL, is a locking method used in concurrent systems.The rules for 2PL are similar to those of Strict 2PL:
# If a transaction T wants to read/write an object, it must request a shared/exclusive lock on the object.
# A transaction cannot request additional locks on any object once it releases any lock, and it can release locks at any time (not only at commit time, as in Strict 2PL).So, every transaction has a growing phase (it acquires locks) and a shrinking phase (it releases locks). 2PL allows only conflict serializable schedules, but doesn't guarantee that
deadlock s will be avoided.2PL is one scheduling algorithm, sometimes used instead of:
*simultaneous locking, simultaneous release (Disadvantage: redundant locking, no interactive transactions)
*incremental locking, simultaneous release (Disadvantage: Deadlock)
*simultaneous locking, incremental release (Disadvantage: rollback, redundant locking)
*incremental locking, incremental release (Disadvantage: deadlock, rollback)External links
* [http://www-stud.uni-due.de/~selastoe/?mdl=dbms&mode=strict automatic schedule solver and generator] by Laurens Stötzel, University of Duisburg-Essen, Germany
Wikimedia Foundation. 2010.