Hamish Burke | 2025-06-16

Related to: #databases


Concurrency Control Mechanism

Lock based protocols

T1 T2 comments
read_item(Saving);
read_item(Saving); Fails
write_item(Savings + 100);
commit now another transaction can write

Two-Phase Locking (2PL)

T1 T2 Comments
lock(Saving) T1 acquires lock
read_item(Saving)
lock(Saving) T2 waits (T1 holds lock)
write_item(Saving)
unlock(Saving) T1 releases lock (shrinking)
lock(Saving) T2 acquires lock
read_item(Saving)
unlock(Saving)