title: Thread Pool C++
body: <p>I have the following <code>for</code> loop:</p>
  <pre><code>for (int i = 0; i &lt; 100; i++) {
      someJob();
  }
  </code></pre>
  <p>I want to run this function only with 5 threads, how can I do it?<br />
  I can't use any external library.</p>
  <p>What I've tried is to make an array with 5 threads and if the index is equal to 5 to wait all threads and do it again, but I'm sure there is another way to do that:</p>
  <pre><code>std::thread t[THREAD_COUNT];
  int j=0;
  
  for (int i = 0; i &lt; 100; i++) {
      t[j++] = std::thread(someJob);
      if (j == THREAD_COUNT)
      {
          for (int k = 0; k &lt; THREAD_COUNT; k++)
          {
              if (t[k].joinable())
                  t[k].join();
          }
          j = 0;
      }
  }
  </code></pre>
  <p>Any suggestion? (I can't use boost)</p>
  <p>Thanks!</p>