Schedule Simulator
Lock Compatibility
Deadlock Detection
S Shared (read)
X Exclusive (write)
Denied
t = 0
Select a schedule and step through it to see 2PL in action.
Lock Manager Table
Granted locks / Waiting
Object → [holders] / [waiters]
No locks held
Schedule
Step Controls
t = 0
2PL Rules
Growing Phase:
• Acquire any lock
• Cannot release yet

Shrinking Phase:
• Release locks
• Cannot acquire new locks

Strict 2PL:
• Hold ALL locks until
  commit/abort
• Prevents cascading aborts
Compatibility Matrix
Req\HeldS-LOCKX-LOCKnone
S-LOCK
X-LOCK
Lock Compatibility Demonstrator

Multiple transactions can hold S-locks simultaneously. An X-lock requires exclusive access.

Transaction T1
Transaction T2
Lock State
No locks held
Click buttons to request/release locks on objects A and B.
Rules
S + S: Both granted ✓
S + X: X must wait ✗
X + S: S must wait ✗
X + X: Second must wait ✗

Shared = read-only
Exclusive = read + write

Upgrade: S → X only if
you are the sole S-holder
Build a waits-for graph. A cycle = deadlock.
Lock State
No locks
Waits-For Graph
No waits
Run a scenario to see how deadlocks form and how they are detected.
Deadlock Scenarios
Detection Methods
Waits-For Graph:
Build directed graph: Ti→Tj if Ti waits for Tj to release a lock.
Deadlock ↔ cycle in graph.

Resolution:
• Abort youngest txn (victim)
• Or use timeouts

Prevention:
• Wait-Die: older waits, younger dies
• Wound-Wait: older wounds younger