title: Is it safe to remove the c++ volatile here?
body: <p>Is it safe to remove <code>volatile</code> from the definition of <code>m_flag</code> here? 
  If <code>m_flag</code> is not volatile, what would stop compilers from optimizing away this loop's condition: <code>while (!m_flag) m_cv.wait(lock);</code> ?
  Does the standard (post-C++11) specify explictly that such optimizations are prohibited in such cases?</p>
  
  <pre><code>#include &lt;mutex&gt;
  #include &lt;condition_variable&gt;
  #include &lt;future&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  class foofoo
  {
      volatile bool m_flag;
      mutex m_mutex;
      condition_variable m_cv;
  
  public:
      void DoWork()
      {
          m_flag = false;
          unique_lock&lt;mutex&gt; lock(m_mutex);
          auto junk = async(std::launch::async, [this]()
          {
              {
                  unique_lock&lt;mutex&gt; lock(m_mutex);
                  m_flag = true;
              }
              m_cv.notify_one();
          });
          while (!m_flag) m_cv.wait(lock);
          cout &lt;&lt; "ququ" &lt;&lt; endl;
      }
  };
  
  int main()
  {
      foofoo f;
      f.DoWork();
  }
  </code></pre>