This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2259|Reply: 0

Shared lock and exclusive lock question analysis

[Copy link]
Posted on 11/8/2024 1:35:40 PM | | | |
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.







Previous:Redundant technology in computers
Next:.NET/C# calculates the area of a polygon
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com