I have tried threadpool.  It is my understanding that the code fragment below should run in constant time independent of the number of threads (assuming that the “Test::operator()” method runs in constant time).  However, I observe an increase in runtime as I increase the pool size from say 1 to 5.

Any thoughts on this?

James

int main()
{
  const int nt = 5;
  const int nit = 10000;

  time_t t1 = clock();

  boost::threadpool::pool p(1);
  for( int j=0; j<nit; ++j ){
    for( int i=0; i<nt; ++i ){
      p.schedule( Test(i) );
    }
    p.wait();
  }

  std::cout << "t=" << difftime(clock(), t1) << std::endl;
  return 0;
}