Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Avoid Deadlocks in Transfers

Two sessions transfer money between accounts 1 and 2 in opposite directions at the same time and deadlock. Show how to lock the rows so that a deadlock cannot occur.

Table schema

Accounts(id INT PRIMARY KEY, balance INT)

Sample data

Session A: transfer 1 -> 2; Session B: transfer 2 -> 1

Discussion

No discussions yet.

Rewards · v2.1

Join Shalyam Newsletter

Get exclusive insights with every issue: education, research and innovation news.

One email a week. Unsubscribe any time.