title: Smart contracts: If i call a function that is using a public variable, can it be modified by the call of a function of other user?
body: <p>I am making a decentralized crowd funding smart contract in solidity to learn more about the language.</p>
  <p>The contract is able to store many crowdfunding projects in a mapping that looks like this</p>
  <pre><code>struct CrowdFundingProject{
      address author,
      string description,
      string title,
      uint goal,
      bool exists
  }
  mapping(uint, CrowdFundingProject) public projects;
  uint lastProject = 0;
  </code></pre>
  <p>the key of the mapping is an autoincremented number. When you create a project it looks like this:</p>
  <pre><code>function createProject(string title, string desc, uint goal) public{
      CrowdFundingProject newProject;
      newProject.author = msg.sender;
      newProject.title = title;
      newProject.description = desc;
      newProject.goal = goal;
      newProject.exists = true;
      lastProject += 1;
      projects[lastProject] = newProject;
  }
  </code></pre>
  <p>But i belive that this could cause problems, for example, if user A ran the function createProject and just when the EVM is executing <code>lastProject += 1;</code> User B runs the function too, making that if <code>lastProject</code> was equal to 100 it is now 101 at the same time that <code>projects[lastProject] = newProject;</code> wasn't done executing for user A, both would have a project with the ID 101. which would overwrite the project for user A and just leave the one for user B.</p>
  <p>Is this correct? If so, my other approach is instead of directly adding the project as <code>project[lastProject]</code> it would be better to do something like</p>
  <pre><code> lastProject += 1;
   uint myProjectsId = lastProject - 1;
   projects[myProjectsId] =  newProject;
  </code></pre>
  <p>I don't know if this approach would cause any sort of error, or if the overwriting error is even possible, so i want to make sure:</p>
  <p>Can an error like the overlapping IDs happen?
  If so: Would the second approach that I proposed come with any weird behavior?</p>