Lock-Compatibility Matrix
S | X | |
S | True | False |
X | False | False |
Here, only S and S are compatible.
This Compatibility function works as follows :
A and B represent some arbitrary lock modes.( A = S/X and B = S/X).
Let’s say, a lock of mode A is requested by transaction Ti on item Q on which Transaction Tj (Ti ≠ Tj) currently holds a lock of mode B.
If transaction Ti can be granted a lock on Q immediately, even though there is a lock on mode B, then we say mode A is compatible with mode B.
Example-1: A and B are two accounts that are accessed by transactions T1 and T2.
Transaction T1 : lock-X(B) ;
read (B) ;
B = B – 50 ;
write (B) ;
unlock (B) ;
lock-X(A) ;
read (A) ;
A = A + 50 ;
write (A) ;
unlock (A) ;
Here, in this transaction T1 transfers Rs. 50 from Account-B to Account-A. And the total amount of money present in accounts A and B is displayed by Transaction T2.
i.e., A + B.
Transaction T2 : lock-S(A) ;
read (A) ;
unlock (A) ;
lock-S(B) ;
read (B) ;
unlock (B) ;
display ( A + B ) ;
Schedule-1 :
T1 | T2 | Concurrency Control Manager |
Lock-X (B) | ||
grant-X (B, T1) | ||
read (B) ; B = B – 50 ; write (B) ; unlock (B) ; | ||
lock-S (A) | ||
grant-S (A, T2) | ||
read(A) unlock(A) lock-S (B) | ||
grant-S (B, T2) | ||
read(B) unlock(B) display (A + B) | ||
lock-X (A) | ||
grant-X(A, T1) | ||
read(A) A = A – 50 write (A) unlock (A) |
Let’s take another example to understand this topic better in the next article
Reference Link