Implementation of Atomic operations
- Dekker's Algorithm
- needs atomic read and writes to main memory
- Hard to implement if more than two transactions are involved
- Use busy waiting
- Spin- Lock
- Need hardware support – should be able lock bus (communication channel between CPU and memory + any other devices) for two memory cycles (one for reading and one for writing). During this time no other devices’ access is allowed to this memory location.
- use busy waiting
- Algorithm does not depend on the number of processes
- Efficient if the lock contentions are low
Deadlock
In deadlock situation, each member of the deadlock processes is waiting for another member to release the resources it wants
- Solution:
- Have enough resources so that no waiting occurs
- Linearly order the resources and request of resources should follow this order.
- Periodically check the resource dependency graph for cycles
- Allow a transaction to wait ofr certain maximum time on a lock and force it to rollback
Probability of Deadlocks
- Assumption
- number of transactions n+1 = n where n is large
- each transaction access r locks exclusively
- Total number of records in the database = R
- On average each transaction is holding r/2 locks approximately
-
Average number of locks taken by the other n transactions = n*(r/2)
Capture.PNG
网友评论