Programming Tutorials

Wait-Die vs Wound-Wait in DBMS: Rules, Examples and Differences

"Wait-Die" and "Wound-Wait" schemes in DBMS in simple terms

Wait-Die and Wound-Wait are timestamp-based deadlock prevention schemes used with database locking. Both give priority to older transactions, but they handle a conflicting lock request differently: in Wait-Die, an older requester waits and a younger requester is rolled back; in Wound-Wait, an older requester aborts the younger lock holder, while a younger requester waits.

The easiest way to remember the difference is: Wait-Die = older waits, younger dies. Wound-Wait = older wounds, younger waits. This guide explains the rules, worked examples, why the schemes prevent deadlocks, and the points commonly tested in DBMS exams.

Advertisement

What are Wait-Die and Wound-Wait in DBMS?

Both schemes are deadlock prevention techniques used by a lock manager when a transaction requests a data item that is already held with an incompatible lock by another transaction. Instead of allowing arbitrary waiting, the manager compares the transactions’ timestamps and decides whether the requester may wait or one transaction must be rolled back.

When a transaction starts, it receives a unique timestamp, written as TS(T). A smaller timestamp means the transaction is older and has higher priority; a larger timestamp means it is younger. For example:

Advertisement
  • T1 (TS = 10) is older.
  • T2 (TS = 20) is younger.

The timestamp order is retained when an aborted transaction is restarted under these schemes. This is important because a restarted transaction should not lose the priority it had when it first entered the system.

1. Wait-Die Scheme (Non-Preemptive)

Wait-Die is called non-preemptive because a transaction does not forcibly take a lock away from another transaction. The lock holder is allowed to continue; the timestamp rule determines whether the requester can wait.

Rules of Wait-Die

  • Older requester, younger lock holder: the older transaction is allowed to wait.
  • Younger requester, older lock holder: the younger requesting transaction is aborted (it “dies”) and can be restarted later with its original timestamp.

Memory tip: In Wait-Die, the older transaction waits, while the younger transaction dies.

Wait-Die example

Assume T1 has timestamp 10 and T2 has timestamp 20. T1 is older than T2.

  1. T1 requests a lock on a data item currently held by T2. Because T1 is older, T1 waits.
  2. If T2 requests a lock held by T1, T2 is younger than the lock holder. The DBMS aborts T2 and releases the locks held by it.
  3. Once the required lock is released, T1 can continue. T2 may be restarted later with timestamp 20.

The two requests can be part of a potential circular wait: for example, T1 may hold lock A while requesting B, and T2 may hold B while requesting A. The Wait-Die rule aborts the younger requester rather than allowing both transactions to wait indefinitely.

2. Wound-Wait Scheme (Preemptive)

Wound-Wait is called preemptive because an older transaction can force a younger transaction holding a required lock to roll back. The younger transaction is “wounded”; its locks are released so the older transaction can proceed.

Rules of Wound-Wait

  • Older requester, younger lock holder: the older transaction wounds the younger lock holder. The younger transaction is aborted and may be restarted with its original timestamp.
  • Younger requester, older lock holder: the younger requesting transaction must wait.

Memory tip: In Wound-Wait, the older transaction wounds the younger one, while the younger transaction waits for the older one.

Wound-Wait example

Again, assume T1 has timestamp 10 and T2 has timestamp 20.

  1. T1 requests a lock currently held by T2. Since T1 is older, it wounds T2.
  2. The DBMS rolls back T2 and releases its locks. T1 can then obtain the required lock, subject to the lock manager’s normal checks.
  3. If T2 requests a lock held by T1, T2 is younger and must wait instead of aborting T1.

In a potential circular-wait situation, the older transaction can break the dependency by aborting the younger lock holder. The older transaction is not made to wait for a younger transaction under this rule.

Worked example: How both schemes prevent a deadlock

Consider two transactions that each hold one exclusive lock:

  • T1 (TS = 10) holds lock A.
  • T2 (TS = 20) holds lock B.
  • T1 requests B, while T2 requests A.

Without a prevention rule, T1 could wait for T2 to release B while T2 waits for T1 to release A. That creates a circular wait.

What happens under Wait-Die?

  1. T1 is older and requests B, which T2 holds. T1 is allowed to wait.
  2. T2 is younger and requests A, which T1 holds. T2 is aborted under the Wait-Die rule.
  3. T2 releases B. T1 can acquire B and continue. T2 can be retried later with its original timestamp.

What happens under Wound-Wait?

  1. T1 is older and requests B, which T2 holds. T1 wounds T2.
  2. T2 is rolled back and releases B. Any pending lock request made by T2 is also cancelled as part of the rollback.
  3. T1 can acquire B and continue. T2 can be retried later with its original timestamp.

Both schemes break the potential cycle, but they do so at different points: Wait-Die aborts a younger requester, whereas Wound-Wait lets an older requester abort a younger lock holder.

Key differences between Wait-Die and Wound-Wait

Aspect Wait-Die Wound-Wait
Type Non-preemptive Preemptive
Older requester asks for a younger transaction’s lock Older requester waits Younger lock holder is aborted (wounded)
Younger requester asks for an older transaction’s lock Younger requester is aborted (dies) Younger requester waits
Which transaction is rolled back? The younger requester The younger lock holder when wounded by an older requester
Who is allowed to wait? Older transaction waits for younger transaction Younger transaction waits for older transaction
How the rule breaks a potential cycle Prevents a younger transaction from waiting for an older one Prevents an older transaction from waiting for a younger one

Why do Wait-Die and Wound-Wait prevent deadlocks?

A deadlock in a lock-based system is represented by a cycle in a wait-for graph. Each node represents a transaction, and an arrow from one transaction to another means the first transaction is waiting for a lock held by the second.

  • Wait-Die: a transaction can wait only when it is older than the lock holder. Every wait edge therefore goes from an older transaction to a younger one. Timestamps strictly increase along a chain of waits, so the chain cannot return to its starting transaction and form a cycle.
  • Wound-Wait: a transaction can wait only when it is younger than the lock holder. Every wait edge therefore goes from a younger transaction to an older one. Timestamps strictly decrease along a chain of waits, so a cycle cannot form.

In both cases, the timestamp ordering makes circular waiting impossible. A transaction may still be delayed or rolled back, but the permitted wait relationships cannot form a deadlock cycle.

Advantages and limitations

Advantages

  • Both schemes prevent deadlocks in the lock-wait relationships they govern.
  • The rules are based on transaction timestamps, giving the lock manager a consistent priority order.
  • Restarting an aborted transaction with its original timestamp preserves its priority.

Limitations

  • A transaction may be rolled back even when a deadlock cycle has not yet formed. These are prevention rules, not a check that a deadlock already exists.
  • Rollback can waste work already performed by the aborted transaction.
  • Wait-Die may cause a younger transaction to be aborted repeatedly before it obtains a required lock.
  • Wound-Wait can also discard work by aborting a younger lock holder when an older transaction needs its lock.

Keeping the original timestamp after a restart is intended to reduce starvation by preserving the transaction’s age and priority. It is not a guarantee against every delay in every implementation; progress also depends on scheduling, transaction duration and the lock manager.

Important exam points

  • A smaller timestamp represents an older transaction.
  • Wait-Die: older waits; younger aborts.
  • Wound-Wait: older aborts the younger lock holder; younger waits.
  • Wait-Die is non-preemptive; Wound-Wait is preemptive.
  • An aborted transaction is restarted with its original timestamp in the standard schemes.
  • Both are deadlock prevention schemes based on transaction timestamps.

Frequently asked questions

1. Which transaction is older: one with timestamp 10 or timestamp 20?

The transaction with timestamp 10 is older because a smaller timestamp represents an earlier transaction.

2. Does Wait-Die abort the older transaction?

No. If an older transaction requests a lock held by a younger transaction, the older transaction waits. A younger requester that asks for a lock held by an older transaction is aborted.

3. What is the main difference between Wait-Die and Wound-Wait?

Wait-Die makes an older requester wait and aborts a younger requester. Wound-Wait allows an older requester to abort a younger lock holder, while a younger requester waits for an older lock holder.

4. Why does a restarted transaction keep its original timestamp?

Keeping the original timestamp preserves its age and priority. If it received a new timestamp on every restart, it could continually become younger and be selected for rollback again.

5. Are Wait-Die and Wound-Wait timestamp-ordering protocols?

They use timestamps, but they are specifically lock-based deadlock prevention schemes. The basic timestamp-ordering concurrency-control protocol is a different technique that checks read and write operations against data-item timestamps.

Conclusion

Wait-Die and Wound-Wait both use transaction age to prevent deadlocks, but their rules are opposites. Remember “Old waits, young dies” for Wait-Die and “Old wounds, young waits” for Wound-Wait. If you first identify which transaction is the requester and which one holds the lock, then compare their timestamps, you can solve most exam questions without confusing the two schemes.

Further reading

RochakGuy

Hi, I'm Piyush and I'm a passionate blogger. I love sharing my insights on Rochaksite.com. I'm committed to providing practical and informative content that helps readers achieve their goals and make informed decisions. When I'm not writing, I enjoy exploring new topics and trends in Technology and indulging in my personal hobbies and interests.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button