Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: illiki23 on November 30, 2017, 05:38:15 PM



Title: How does Ethereum deal with race conditions?
Post by: illiki23 on November 30, 2017, 05:38:15 PM
I am curious how Ethereum deals with race conditions.  

For example take this code:

function () payable {
       uint valueToPass = safeMath.div(msg.value,10**13);
       if (balances[ownerAddress] >= valueToPass && valueToPass > 0) {
           balances[msg.sender] = safeMath.add(balances[msg.sender],valueToPass);
           balances[ownerAddress] = safeMath.sub(balances[ownerAddress],valueToPass);

           Transfer(ownerAddress, msg.sender, valueToPass);
       }
   }

It increases the balance of the sender before decreasing the balance of the recipient. What happens if multiple calls to payable are made simultaneously with the same addresses?  Could it possibly allow something like double spend attacks?

Does Ethereum use semaphores such as mutexes?  How do they prevent race conditions?