Two updates, one price: compare-and-set
transcript
Two people update the same price at the same time. How do you keep both updates, without a lock?
A reads the price. It says 50. B reads it too, a moment later. Also 50.
A sets 55, but only if it's still 50. It is, so the write goes through. B sets 60, but only if it's still 50. It isn't any more. Refused. B reads again, gets 55, and tries again. This time it works.
A plain write would let B overwrite A. B's number was worked out from a stale 50. A is lost, and nobody notices. Compare and set refuses it, so B has to look again.
Ride sharing uses it: if the driver is still free, take them. And the key-value store checks versions at commit.
No lock held, and nobody waits. If you lose the race, look again and retry. No update is lost.
Full breakdown in the lecture.