title: Multithreaded access to global variable : should I use mutex
body: <p>Suppose I have 2 threads : <code>std::thread thd1; std::thread thd2;</code> Thread thd1 periodically sets some global variable calling the folowing <code>setFlag</code> function :</p>
  
  <pre><code>static std::int32_t g_flag;
  static std::mutex io_mutex;
  
  void setFlag( std::int32_t flag )
  {
     //std::lock_guard&lt;std::mutex&gt; lk(io_mutex);
     g_flag = flag;
  }
  </code></pre>
  
  <p>And thread thd2 periodically reads this flag</p>
  
  <pre><code>std::int32_t getFlag()
  {
     //std::lock_guard&lt;std::mutex&gt; lk(io_mutex);
     return g_flag;
  }
  </code></pre>
  
  <p>The question is - should I use mutex in this case? Is it safe to access variable in read-write manner from several threads without having mutex?</p>