title: C++ - Thread Pool
body: <p>for a university exercise I had to build a thread pool using classes. I started working on it but I encounterd some problems.
  My idea was to use ASYNC to generate the threads but compiler told me that the function that I had to provide to async should have been a static function. The problem was that if the main function of the thread was static also every variable had to be static and the threads can't reference all the variables mutex included.
  After some tries I came out with this solution but I don't know if it's good to proceed like that</p>
  
  <pre><code>class JobScheduler01 {
  private:
      unsigned int numOfThread;
      std::vector&lt;std::future&lt;int&gt;&gt; pool;
      //std::vector&lt;std::thread&gt; pool_thread;
  
      std::list&lt;Job&gt; runningQueue;
      std::list&lt;Job&gt; waitingQueue;
  
      int ThreadMain(); // &lt;- infinite loop
  
      std::mutex m;
  public:
  
      JobScheduler01();
      ~JobScheduler01();
      void Start(); // &lt;- start all the threads
  };
  </code></pre>
  
  <pre><code>void JobScheduler01::Start() {
      for(unsigned int i = 0; i &lt; numOfThread; i++){
          pool.push_back(std::async([this](){return ThreadMain();})); // &lt;------ QUESTION
      }
  }
  
  int JobScheduler01::ThreadMain() {
      // main loop here
      m.lock();
      std::cout &lt;&lt; "thread: " &lt;&lt; std::this_thread::get_id() &lt;&lt; "\n";
      m.unlock();
      return 0;
  }
  </code></pre>
  
  <p>I created a lambda fuction that just start the main loop, but I'm not sure if it's right.
  Does this apporoach generate some sort of monsters? or is it ok?
  Which could be a better solution? 
  Is it better to use async or to ue std::thread and join them in the destructor?</p>