In a multi-user shared system, multiple users operating on the same data may lead to data inconsistency, so locking operations are required in concurrent operations to control the concurrent execution of transactions.
Shared Lock:As can be seen from the name, the lock can be shared, the write operation must not be shared, as soon as the shared data is written randomly, there is no "lock" to speak of, so the shared lock is the read operation "sharing", that is, the lock can no longer be written after the addition of this lock, but it can be read, it can also be called a read-only lock.
Exclusive locks:The exclusive lock is more domineering, as long as I add this lock, other operations cannot be carried out, why? Because I want to modify the data, since I want to modify it, I must not let others modify it again, and I must not add a read-only lock, because with a read-only lock, I cannot perform write operations.
For example, if transaction T1 adds a shared lock to data D1, and transactions T2 and T3 add exclusive locks to data D2 and D3 respectively, then transaction T1 adds a shared lock to data (51). Transaction T2 pair data (52).
(51) Answer: D
A. D2 and D3 plus the lock are successful B. D2, D3 plus shared lock are successful C. D2 plus the shared lock succeeds, D3 adds it lock fails D. D2, D3 plus exclusive locks and shared locks all fail
(52) Answer: C
A. D1, D3 plus the shared lock all failed B. D1, D3 plus shared lock are successful C. D1 plus shared lock succeeded, D3 added another lock failed D. D1 plus the lock succeeded, and D3 failed to add the shared lock
If there is a shared lock, you can add a shared lock, but you cannot add an exclusive lock. If there is an exclusive lock, then neither the shared lock nor the exclusive lock can be added.
|