Week 11 DBMS Online Lecture Lock Based Protocol
Week 11 DBMS Online Lecture Lock Based Protocol
Types of lock
Binary locks- Lock with two states (Locked and
unlocked)
Shared or exclusive locks
2
Shared or Exclusive locks
3
Problem with locking
4
Lock based protocol
5
Shared or Exclusive locks
6
Lock-Based Protocols (Cont.)
Lock-compatibility matrix
7
Lock-Based Protocols (Cont.)
8
Two Phase Locking Protocol
9
Two Phase Locking Protocol
1
0
Lock Conversion
1
1
Automatic Acquisition of Locks
1
2
Automatic Acquisition of Locks
1
3
Deadlocks
System is deadlocked if there is a set of transactions such that every
transaction in the set is waiting for another transaction in the set
Consider the partial schedule
Read(A)
write(A)
1
5
Conditions to Occur Deadlock
1
6
Conditions to Occur Deadlock cont..
1
7
Conditions to Occur Deadlock
Mutual Exclusion
It implies if two processes cannot use the same resource at the
same time
1
8
Conditions to Occur Deadlock
1
9
Conditions to Occur Deadlock
Circular Wait
All the processes must be waiting for the resources in a cyclic
manner so that the last process is waiting for the resource
which is being held by the first process
T1
T2
T4
T3
2
0
Problems of Deadlocks
2
1
Deadlocks avoidance and Handling
2
2
Deadlocks avoidance and Handling
Rigorous two-phase locking is even stricter. Here, all locks are held
till commit/abort. In this protocol transactions can be serialized in
the order in which they commit.
2
3
Deadlocks Prevention
2
4
Deadlocks Prevention cont…
2
5
Deadlocks Prevention cont…
2
6
Deadlocks Prevention cont…
Timeout-Based Schemes:
a transaction waits for a lock only for a specified amount of
time. If the lock has not been granted within that time, the
transaction is rolled back and restarted,
Thus, deadlocks are not possible
simple to implement; but starvation is possible. Also difficult to
determine good value of the timeout interval.
2
7
Thank You