Author

Topic: How does Ethereum deal with race conditions? (Read 162 times)

sr. member
Activity: 602
Merit: 295
Hail Eris!
November 30, 2017, 12:38:15 PM
#1
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?  
Jump to: