title: Why is threading dangerous?
body: <p>I've always been told to puts locks around variables that multiple threads will access, I've always assumed that this was because you want to make sure that the value you are working with doesn't change before you write it back
  i.e.</p>
  
  <pre><code>mutex.lock()
  int a = sharedVar
  a = someComplexOperation(a)
  sharedVar = a
  mutex.unlock()
  </code></pre>
  
  <p>And that makes sense that you would lock that. But in other cases I don't understand why I can't get away with not using Mutexes.</p>
  
  <p>Thread A:</p>
  
  <pre><code>sharedVar = someFunction()
  </code></pre>
  
  <p>Thread B:</p>
  
  <pre><code>localVar = sharedVar
  </code></pre>
  
  <p>What could possibly go wrong in this instance? Especially if I don't care that Thread B reads any particular value that Thread A assigns.</p>