Concurrency Control Chapter
Concurrency Control Chapter
• Lock-Based Protocols
• Timestamp-Based Protocols
Lock-Based Protocols
• A lock is a mechanism to control concurrent access to a
data item
• Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as
well as
written. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is
requested using lock-S instruction.
• Lock requests are made to concurrency-control manager.
Transaction can proceed only after request is granted.
Lock-Based Protocols (Cont.)
• Lock-compatibility matrix
• Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for
T3 to release its lock on B, while executing lock-X(A) causes T3 to wait for T4 to
release its lock on A.
• Such a situation is called a deadlock.
• To handle a deadlock one of T3 or T4 must be rolled back
and its locks released.
If we do not use locking, or if we unlock data
items as soon as possible after reading or
writing them, we may get inconsistent states.
On the other hand, if we do not unlock a data
item before requesting a lock on another data
item, deadlocks may occur
Pitfalls of Lock-Based Protocols (Cont.)
transaction transactio
with smaller n
timestamp with larger
timestamp