Strict Two-Phase Locking
Lock implementation
Locking
lock(transaction, object, lock_mode)
{
lock_granted = false
while not lock_granted {
// lock_entry() creates a lock entry if needed
entry = lock_entry(object)
if grant_lock_immediately(entry, lock_mode) {
entry.transaction = transaction
entry.lock_mode = lock_mode
lock_count += 1
lock_granted = true
} else {
if transaction not in queue {
queue.add_waiter(transaction, lock_mode)
}
wait()
}
}
}
|