
Hi -
I'm using asio::io_service as a dispatcher for a thread pool. I'm
wondering how I can synchronize the threads after I post the tasks to
the io_service.
I tried using a barrier but it doesn't always work correctly. The
barrier waits indefinitely; although I verified the post() function
gets called, the io_service doesn't seem to dispatch anything.
I've also thread using the boost::threadpool library but the overall
speed is slower.
I'd appreciate any insight on what I'm doing wrong with the barrier or
any other high performance thread pooling alternatives.
Thanks,
Daren
<code>
void handler ( int i, int nSize, double *pArray, double *pTemp,
boost::barrier *pBarrier )
{
// compute on pArrray --> write result to pTemp[i]
....
pBarrier->wait();
}
double doCalc ( int nSize, double *pArray, double *pTemp )
{
unsigned int nNumThreads = 8;
int nSubSize = nSize / nNumThreads;
boost::barrier barrier( nNumThreads + 1 );
for( int i=0;i