I noticed that my applications often write values to a database that depend on a former read operation. A common example is a bank account where a user could deposit money:
void deposit(amount) {
balance = getAccountBalance()
setAccountBalance(balance amount)
}
I want to avoid a race condition if this method is called by two threads/clients/ATMs simultaneously like this where the account owner would lose money:
balance = getAccountBalance() |
| balance = getAccountBalance()
setAccountBalance(balance amount) |
| // balance2 = getAccountBalance() // theoretical
| setAccountBalance(balance amount)
V
I often read that Repeatable Read or Serializable can solve this problem. Even the
Sorry it is in franch, but I think it is readable...