Bitcoin Forum
May 14, 2024, 10:47:14 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How does Ethereum deal with race conditions?  (Read 141 times)
illiki23 (OP)
Sr. Member
****
Offline Offline

Activity: 602
Merit: 295


Hail Eris!


View Profile
November 30, 2017, 05: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?  

             ▄▄██████▄
         ▄▄████████████
   ▄▄█████████▀▀   ▀████
 ▄███████████▄      ████
████▀   ▀▀██████▄▄▄████
████      ▄███████████▄
▀████▄▄▄████████▀▀▀████▄
 ▀███████████▀      ████
 ████▀▀▀██████▄▄   ▄███▀
████      ▀███████████▀
████▄   ▄▄█████████▀▀
 ████████████▀▀
  ▀██████▀▀
█████████████████

     ███

██████████

     ██████

███████████

     ███████████████

███████████████████
█████████████████

███    

██████████

██████    

███████████

███████████████    

███████████████████
▄█████████████████████████▄
███████████████████████████
███████████████████████████
██████▀███████▀   ▀▀▀▄█████
█████▌  ▀▀███▌       ▄█████

████▀               █████
█████▄              ███████
██████▄            ████████
███████▄▄        ▄█████████
█████▄▄       ▄████████████
███████████████████████████
███████████████████████████
▀█████████████████████████▀
▄█████████████████████████▄
███████████████████████████
███████████████████████████
██████████████████▀▀███████
█████████████▀▀▀    ███████

███████▀▀▀   ▄▀   ███████
█████▄     ▄█▀     ████████
████████▄ █▀      █████████
█████████▌▐       █████████
██████████ ▄██▄  ██████████
████████████████▄██████████
███████████████████████████
▀█████████████████████████▀
▄█████████████████████████▄
███████████████████████████
███████████████████████████
███████▀           ▀███████
██████  ▄██▀▀▀▀▀█▀▄  ██████

█████  █▀  ▄▄▄  ▀█  █████
██████  █  █████  █  ██████
██████  █▄  ▀▀▀  ▄█  ██████
██████  ▀██▄▄▄▄▄██▀  ██████
███████▄           ▄███████
███████████████████████████
███████████████████████████
▀█████████████████████████▀
▄█████████████████████████▄
███████████████████████████
███████████████████████████
██████████▀█████▀██████████
███████▀  ▀     ▀  ▀███████

█████▌             ▐█████
██████    ██   ██    ██████
█████▌    ▀▀   ▀▀    ▐█████
██████▄  ▄▄▄   ▄▄▄  ▄██████
████████▄▄███████▄▄████████
███████████████████████████
███████████████████████████
▀█████████████████████████▀


na]][/font][/font][/size][/font][/td][td][/td][/tr][/table][/tr
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!