In a transaction, a data item which we want to read or write should first be locked before any read or write operation. After the operation is over, the transaction unlocks the data item so that other transactions can lock that same data item for their use.
Let us see how locking mechanisms help us to create error free schedules.
An erroneous schedule is as follows −
Here t2 reads A, before A is modified in T1. This will result in inconsistency.
Now we use locking mechanism in the above schedule which is shown below −
Until T1 performs Unlock(A) T2 cannot access A. So, the inconsistency is removed automatically, and the schedule becomes a correct schedule. The use of locks helps to create a correct concurrent schedule.