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.