In a popular sale contract, what would happen if the following code was true?
totalNumberOfTokensDistributed = 0;
totalNumberOfTokensAvailable = 100;
function claimTokens() {
uint tempTotalCollected = totalNumberOfTokensDistributed + 2;
require(tempTotalCollected <= totalNumberOfTokensAvailable);
totalNumberOfTokensDistributed = tempBeingCollected
// Address that calls function gets 2 tokens
}
The function allows the creator the check if the function call will not be over than the total number available. If two or more users were to call this function in the same block, how would totalNumberOfTokensDistributed = tempBeingCollected
behave? If 4 users called this function in one block, would totalNumberOfTokensDistributed
be 8? Or would it be overwritten by every use and only end at 2?
I know a solution is totalNumberOfTokensDistributed += 2;
, but I am curious about race conditions in Solidity.