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

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.