title: How to make class static variable thread safe
body: <p>I have a class like so:</p>
  
  <pre><code>class Test
  {
  private:
      Test() {}
      static bool is_done;
      static void ThreadFunction();
  public:
      static void DoSomething();
  }
  
  
  bool Test::is_done = true;
  
  void Test::DoSomething()
  {
      std::thread t_thread(Test::ThreadFunction);
  
      while (true) {
          if (is_done) {
              //do something else
              is_done = false;
          }
  
          if (/*something happened*/) { break; }
      }
  
      // Finish thread.
      t_thread.join();
  }
  
  void Test::ThreadFunction()
  {
      while (true) {
          if (/*something happened*/) {
              is_done = true;
          }
      }
  }
  </code></pre>
  
  <p>In main I then just call Test::DoSomething(); Is variable 'is_done' in this case thread safe? If its not how can I make reading it safe?</p>