Concurrency and race conditions
What risk does the program face?
Examples
Worked example
Input
Stock is 1. Two orders independently read 1 before either decrements.
Expected output
Both orders may be accepted for the same item.
Hints and solution
Hint 1
Write down the starting state and walk through one example by hand.
Reveal worked answer
Both decisions were based on the same stock value. The check and update need a coordinated boundary.