Similarities and differences between shared locks and exclusive locks

Source: Internet
Author: User

Shared lock (s lock ):

If transaction t adds a shared lock to data a, other transactions can only add a shared lock to data a and cannot apply exclusive locks. Transactions authorized to share locks can only read data and cannot modify data.

Exclusive lock (x lock ):

If transaction t adds an exclusive lock to data a, other transactions cannot block aplus any type. Transactions authorized to exclusive locks can read and modify data.

Briefly explain why a deadlock occurs? What are the main ways to solve deadlocks?

When several transactions wait to release and block each other, they are in an indefinite wait state and the system enters a deadlock.

To solve the deadlock, we should start from two aspects: prevention and elimination:

(1) deadlock prevention method: ① each transaction must block all the data to be used at a time (either completely successful or completely unsuccessful) ② specify the sequence in which the data is blocked, all transactions must be blocked in this order.

(2) allow a deadlock and release it. If a deadlock is found, undo one of the less costly items, roll back the transaction, and release the lock held by the transaction, continue other transactions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.