title: c++ how to use std::mutex and std::lock_guard with functor?
body: <p>I am learning how to use <code>std::thread</code> in standard C++, and I can't solve one problem with <code>std::mutex</code>.</p>
  
  <p>I am running 2 threads with simple functions that show a message in CMD. I want to use a <code>std::mutex</code>, so that one thread will wait until the other threat stops using the buffer. </p>
  
  <p>When I use the functions everything works fine, but with the functors I have a problem:</p>
  
  <blockquote>
    <p>error C2280: 'std::mutex::mutex(const std::mutex &amp;)' : attempting to reference a deleted function</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;mutex&gt;
  
  class thread_guard
  {
      private:
          std::thread m_thread;
      public:
          thread_guard(std::thread t)
          {
              m_thread = std::move(t);
              if (!m_thread.joinable())
                  std::cout &lt;&lt; "Brak watku!!!" &lt;&lt; std::endl;
          }
          ~thread_guard()
          {
              m_thread.join();
          }
  };
  
  class func
  {
      private:
          std::mutex mut;
      public:
          void operator()()
          {           
              for (int i = 0; i &lt; 11000; i++)
              {
                  std::lock_guard&lt;std::mutex&gt; guard(mut);
                  std::cout &lt;&lt; "watek dziala 1" &lt;&lt; std::endl;
              }
          }
  };
  
  class func2
  {
      private:
          std::mutex mut;
      public:
          void operator()()
          {           
              for (int i = 0; i &lt; 11000; i++)
              {
                  std::lock_guard&lt;std::mutex&gt; guard(mut);
                  std::cout &lt;&lt; "watek dziala 2" &lt;&lt; std::endl;
              }
          }
  };
  
  std::mutex mut2;
  
  void fun()
  {   
      for (int i = 0; i &lt; 11000; i++)
      {
          std::lock_guard&lt;std::mutex&gt; guard(mut2);
          std::cout &lt;&lt; "watek dziala 1" &lt;&lt; std::endl;     
      }
  }
  
  void fun2()
  {   
      for (int i = 0; i &lt; 11000; i++)
      {
          std::lock_guard&lt;std::mutex&gt; guard(mut2);
          std::cout &lt;&lt; "watek dziala 2" &lt;&lt; std::endl;
      }
  }
  
  int main(void)
  {
      thread_guard t1( (std::thread( func() )) );
      thread_guard t2( (std::thread(func2() )) );
      //thread_guard t1((std::thread(fun)));
      //thread_guard t2((std::thread(fun2)));
  }
  </code></pre>