title: Volatile member variable
body: <p>I'm working with C++ 11 and I encountered a class with a volatile member variable, which raised a question: </p>
  
  <p>Question 1:</p>
  
  <p>if a member variable is set in one class function and polled in another class function - is there ever a need for volatile? If so, when?
  (I know that if x is mapped to hardware register we should use volatile, I mean a "pure software" scenario)</p>
  
  <p>Example:</p>
  
  <pre><code>class MyClass
  {
  public:
      FuncA { if (x==5) print("hello"); }
      FuncB { x=5;}
  private:
      volatile int x = 0;
  }
  </code></pre>
  
  <p>Different threads are accessing <code>MyClass</code> instance, but no 2 threads at the same time, so no need to guard x.</p>
  
  <p>Question 2:</p>
  
  <p>Is there a scenario (some kind of optimization) that after FuncB is called FuncA will not print "hello"?</p>