title: ThreadPool implemented with OpenMP
body: <p>I need to implement a thread pool executor for generic tasks. My idea is to use OpenMP for thread management. The problem is that I'm not familar yet with OpenMP..</p>
  
  <p>I tried to find an existing implementation of the generic ThreadPool with OpenMP, but I haven't find one so far. What I would like to have in the end is something very similar to <code>java.util.concurrent.ThreadPoolExecutor</code>:</p>
  
  <pre><code>template &lt;typename Return, typename Task&gt;
  class ThreadPoolExecutor
  {
  public:
      ThreadPoolExecutor(int threadCount);
  
      // asyncronous invoke
      boost::unique_future&lt;Return&gt; submit(const TaskPtr &amp; task);
  
      // blocking call
      std::vector&lt;Return&gt; invokeAll(const std::vector&lt;TaskPtr&gt; &amp; tasks)
      {
          // submit all tasks + wait for completion
          #pragma omp parallel default(shared)
          {
              // call tasks here
          }
      }
  };
  </code></pre>
  
  <p>I have several questions about this approach:</p>
  
  <ol>
  <li><p>Is there existing implementation of thread pool with OpenMP for C++? [I know I can implement threadpool with boost::asio::io_service, but I would prefer not depend on it]</p></li>
  <li><p>With my design - how can we guarantee that the OpenMP threads will be 'owned' by the concrete ThreadPoolExecutor instance? They should not be static for all instances.</p></li>
  </ol>
  
  <p>Thank you for any advice &amp; constructive critics of this approach &amp; proposals of other implementations.</p>