Two jobs race on one balance

Job A deposits 50 and job B withdraws 30 from the same account, which holds 100. Each job reads the balance, works for about four seconds, then writes the result. The final balance should be 120. Step through each run with Previous and Next, or the arrow keys; the times are illustrative.

B reads the balance before A has written, so B's write is computed from a read that is four seconds stale and replaces A's deposit.

Each job takes a row lock before it reads. B waits until A has written and unlocked, so B reads 150 and both changes survive.