title: how do I initialise an atomic_flag variable if it is a member of a class?
body: <p>I'm trying to implement a spin lock using an atomic_flag. I know that with C++11 I have to initialise the atomic_flag variable, but I can't get it to compile. My code looks like this:</p>
  
  <pre><code>class SpinLock 
  {
   public:
    SpinLock()
     :m_flag(ATOMIC_FLAG_INIT)  /// syntax error : missing ')' before '{'
    {
    }
  
    void lock()
    {
      while (m_flag.test_and_set() == true){}
    }
  
    void unlock()
    {
      m_flag.clear();
    }
  
   private:
    SpinLock &amp;operator=(const SpinLock &amp;);
  
   private:
    std::atomic_flag    m_flag;
  };
  </code></pre>
  
  <p>When I compile the code I get 'syntax error : missing ')' before '{''. I also see that ATOMIC_FLAG_INIT is defined as {0}, but what is the correct way to write this then?</p>
  
  <p>The following compiles, but is it still threads safe?</p>
  
  <pre><code>  SpinLock()
    {
           m_flag.clear();
    }
  </code></pre>