Introduction
Locking discovers a serialization order at run time, through the order of lock points. Timestamp ordering fixes the order in advance: every transaction gets a unique timestamp when it starts, and the system allows a conflicting operation only if it respects timestamp order. A transaction that would violate the order is rolled back and restarted with a new timestamp. No transaction ever waits, so there are no deadlocks.
Timestamps are also used with locking, to decide who waits and who is rolled back in the wait-die and wound-wait deadlock-prevention schemes. The tasks are to trace the timestamp-ordering rules on a schedule, to apply the Thomas write rule, and to say what happens under wait-die and wound-wait.
Prerequisites
- Lock-Based Concurrency Control and Two-Phase Locking: conflicts, deadlock, and the idea of a serialization order.
Core concepts
Timestamps. is assigned when starts, from a system clock or a counter; if starts before , then . A smaller timestamp means an older transaction.
Item timestamps. For each item :
- : the largest timestamp of any transaction that has successfully written ;
- : the largest timestamp of any transaction that has successfully read .
Both start at 0.
Basic timestamp-ordering (TO) protocol.
- issues :
- if : would read a value written by a younger transaction; reject and roll back ;
- otherwise execute, and set .
- issues :
- if : a younger transaction has already read the old value; reject and roll back ;
- if : would overwrite a younger write; reject and roll back ;
- otherwise execute, and set .
A rolled-back transaction restarts with a new, larger timestamp.
Thomas write rule. Change only the second write test: if (and the read test passed), ignore the write instead of rolling back. The write is obsolete: a younger transaction has already written , and nobody between them read the value would write.
Deadlock prevention with timestamps (used with locking). When requests an item held by :
- Wait-die (non-preemptive): if is older, it waits; if younger, it dies (rolls back).
- Wound-wait (preemptive): if is older, it wounds ( rolls back); if younger, it waits.
In wait-die only older transactions wait for younger ones; in wound-wait only younger transactions wait for older ones. Waits therefore always point in one direction of age, so no cycle can form. A rolled-back transaction keeps its original timestamp, so it eventually becomes the oldest and cannot starve.

How it works: tracing basic TO
For each operation in order: look up the item's and , apply the tests, and either update the timestamps or roll back the transaction. A table with one row per operation and columns for the test, the outcome and the new timestamps keeps the trace honest.
Mathematical explanation
Why TO gives conflict serializability. Every executed pair of conflicting operations is ordered by timestamp: a read is allowed only after writes from older transactions, a write only after reads and writes from older transactions. So every edge of the precedence graph has , the graph is acyclic, and the schedule is conflict equivalent to the serial schedule in timestamp order.
What the Thomas write rule guarantees. The rule in effect deletes each obsolete write from the transaction that issued it. The operations that are actually executed pass every basic TO test, so they are conflict equivalent to the serial schedule in timestamp order. Read with the ignored writes left in place, the submitted schedule need not be conflict serializable: Example 4 is accepted, is not conflict serializable, and is view serializable. Do not stretch this to "every schedule the rule accepts is view serializable as written": a transaction that reads an item after an ignored write by another transaction can make the as-written schedule fail the view test, although the executed schedule is still serializable. A read after its own obsolete ignored write instead fails the timestamp read check and aborts.
Deadlock and starvation. Basic TO never makes a transaction wait, so it is deadlock-free. A long transaction can, however, be rolled back again and again (each restart gets a new, larger timestamp, which can be invalidated again), so starvation is possible.
Recoverability. Basic TO says nothing about commits, so it can produce schedules that are not recoverable or not cascadeless. Strict TO delays a read or write of until the other transaction that last wrote has committed or aborted.
TO and 2PL accept different schedules. Neither set contains the other: TO forces the timestamp order, 2PL forces the lock-point order and the no-acquire-after-release rule (Examples 5 and 6).
Worked examples
Example 1: a full trace. , , ; .
| Operation | Test | Outcome | Item timestamps after |
|---|---|---|---|
| execute | |||
| execute | |||
| , | execute | ||
| execute | |||
| , | execute | ||
| roll back | unchanged |
is rolled back at its last operation: younger and have already read the old .
Example 2: a read rejected. , , . After , ; has , so is rolled back: it would read a value from its future.
Example 3: the read test also beats the Thomas rule. , , . At , , so is rolled back under both basic TO and the Thomas write rule: the Thomas rule relaxes only the write-write test.
Example 4: the Thomas write rule. , , ; , the view-serializable but not conflict-serializable schedule from Schedules and Serializability. At : passes, but . Basic TO rolls back; the Thomas rule ignores , and the schedule completes, view equivalent to .
Example 5: TO accepts a schedule 2PL cannot produce. is not producible by 2PL (lock note, Example 3). With every test passes, and runs under basic TO, equivalent to .
Example 6: 2PL accepts a schedule TO rejects. with . 2PL produces it ( releases its S lock, then takes X), serial order . Basic TO rolls back at , because .
Example 7: wait-die and wound-wait (Figure 1). (older), .
- requests an item held by : wait-die, waits; wound-wait, is rolled back and gets the item.
- requests an item held by : wait-die, dies (rolls back, restarts later with timestamp 10); wound-wait, waits.
With the deadlock of the lock note ( holds and wants , holds and wants ), wait-die lets wait and kills when it requests ; wound-wait rolls back as soon as requests . Either way no cycle forms.
Example 8: the Thomas rule can change who is rolled back. , , ; . Convention: a rolled-back transaction's remaining operations are dropped from the trace, and it is not restarted within it.
| Operation | Basic TO | Thomas write rule |
|---|---|---|
| execute; | execute; | |
| execute; | execute; | |
| : roll back | but : ignore | |
| dropped ( rolled back) | execute; | |
| , : execute; | : roll back | |
| execute; | execute; |
Basic TO rolls back ; the Thomas rule saves by ignoring its obsolete write, but then reads , and that read is what later forces back. Both runs lose exactly one transaction. The Thomas rule never rejects a write that basic TO accepts, but it does not promise fewer rollbacks overall, because the transactions it saves keep running and change the timestamps.
Important properties and observations
- Basic TO: conflict serializable in timestamp order, deadlock-free, starvation possible, not necessarily recoverable.
- Read rule: reject if a younger transaction already wrote the item.
- Write rule: reject if a younger transaction already read or wrote the item.
- Thomas write rule: ignore an obsolete write instead of rejecting; the executed operations are serializable in timestamp order, and some accepted schedules (Example 4) are view serializable but not conflict serializable.
- Restarted transactions get new timestamps in TO but keep old ones in wait-die and wound-wait.
- Wait-die: older waits, younger dies. Wound-wait: older wounds, younger waits.
- TO and 2PL each accept schedules the other rejects.
Common misconceptions.
- "The Thomas write rule ignores any late write." Only when the read test passes; a younger reader still forces a rollback (Example 3).
- "In wait-die the younger transaction waits." The older one waits; the younger dies.
- "TO avoids starvation because it avoids deadlock." Repeated restarts can starve a transaction.
- "A larger timestamp means older." Larger means younger.
GATE examination perspective
- Trace basic TO. Work on a schedule with given timestamps; find the first rollback.
- Thomas write rule. Which writes are ignored, and whether the schedule completes.
- Wait-die versus wound-wait. Who waits and who is rolled back for given timestamps.
- Properties. Serializability, deadlock freedom, starvation and recoverability of each protocol.
- Compare. Combine this with 2PL on schedules accepted by one and not the other.
Summary
Sources
- A. Silberschatz, H. F. Korth, S. Sudarshan, Database System Concepts, 7th ed., McGraw-Hill, 2019 (2020 copyright), 18.2 Deadlock Handling, 18.5 Timestamp-Based Protocols.
- R. Elmasri, S. B. Navathe, Fundamentals of Database Systems, 7th ed., Pearson, 21.1 Two-Phase Locking Techniques for Concurrency Control, 21.2 Concurrency Control Based on Timestamp Ordering.