title: Making a queue of threads in C++
body: <p>I'm trying to run threads one after the other. I know I could do them serially but the whole point is so the commands don't block the UI. </p>
  
  <p>However, in the implementation I came up with, I can't use <code>std::thread</code> because I can't pass threads as a parameter. </p>
  
  <p>Is there another way I can do this? </p>
  
  <hr>
  
  <p>This is my current implementation:</p>
  
  <pre><code>#include &lt;mutex&gt;
  #include &lt;thread&gt;
  #include &lt;queue&gt;
  
  class ThreadQueue {
      std::queue &lt;std::thread&gt; threads;
      std::mutex mutex_add;
      std::mutex mutex_remove;
  
  public:
     ThreadQueue() {}
  
      ~ThreadQueue() {}
  
      void add(std::thread thread) {
          mutex_add.lock();
          threads.push(thread);
          mutex_add.unlock();
      }
  
      std::thread remove() {
          mutex_remove.lock();
          std::thread thread = threads.front;
          threads.pop();
          thread.join();
          mutex_remove.unlock();
      }
  };
  </code></pre>