Recap: Why Concurrency Control?

Solution: Use locking mechanisms to synchronize access to shared data.


Lock Types

Basic Lock Modes

Lock Type Description
Shared (S-LOCK) Allows multiple transactions to read a data item.
Exclusive (X-LOCK) Grants exclusive access to a data item (needed for writes).

Locks vs. Latches

Feature Locks Latches
Scope Used by transactions Used by threads
Protects Database contents In-memory data structures
Held Until End of transaction Short-lived (critical section)
Modes Shared, Exclusive Read, Write
Deadlock Handling Detection & Resolution Avoidance (spinlocks)

Transactions request locks before accessing objects to ensure correctness.


Two-Phase Locking (2PL)

What is 2PL?

2PL ensures transactions execute in a serializable order.


2PL Execution Example