A race condition occurs when two processes race to complete based on an initial condition that becomes invalid while the processes are executing. A classic example is transferring money between bank accounts:
- You have $500 in your bank account, and you need to transfer the entire amount to a friend.
- Using your phone, you log into your banking app and request a transfer of $500 to your friend.
- After 10 seconds, the request is still processing. So you log into the banking site on your laptop, see that your balance is still $500, and request the transfer again.
- The laptop and mobile requests finish within a few seconds of each ...