title: What could happen if two threads access the same bool variable at the same time?
body: <p>I have a cross platform c++ program where I'm using the boost libraries to create an asynchronous timer.<br>
  I have a global variable:</p>
  
  <pre><code>bool receivedInput = false;
  </code></pre>
  
  <p>One thread waits for and processes input</p>
  
  <pre><code>string argStr;
  while (1) 
  {
       getline(cin, argStr);
       processArguments(argStr);
       receivedInput = true;
  }
  </code></pre>
  
  <p>The other thread runs a timer where a callback gets called every 10 seconds. In that callback, I check to see if I've received a message </p>
  
  <pre><code>if (receivedInput)
  {
      //set up timer to fire again in 10 seconds
      receivedInput = false;
  }
  else
      exit(1);
  </code></pre>
  
  <p>So is this safe? For the read in thread 2, I think it wouldn't matter since the condition will evaluate to either true or false. But I'm unsure what would happen if both threads try to set receivedInput at the same time. I also made my timer 3x longer than the period I expect to receive input so I'm not worried about a race condition. </p>
  
  <p>Edit: 
  To solve this I used boost::unique_lock when I set receivedInput and boost::shared_lock when I read receivedInput. I used an example from <a href="https://stackoverflow.com/a/6450576/677432">here</a></p>