Concurrency / bank-management-system
Withdraw the same money twice
assert cash_dispensed <= opening_balance
Two ATMs withdraw 60 from an account holding 100 at the same instant. Correct result: one succeeds, one is refused. The database interleaves their statements however it likes.
- Race with Read, then write. Usually 120 comes out of a 100 account.
- Pick either my code option and race again. Never more than 100.
Race once to see how the two transactions interleave, step by step.