Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost::thread to keep all cores busy
From: Eric J. Holtman (eric_at_[hidden])
Date: 2010-07-26 12:19:01

On 7/26/2010 11:10 AM, Internet Retard wrote:
> 1. Get the number of cores using boost::thread::hardware_concurrency()


> 2. Fill a std::queue container with jobs for the threads.


> 3. While the container is not empty and there are less active threads
> than boost::thread::hardware_concurrency(), then start a new thread.


In the main routine:

Just start N threads, where N is the number retrieved from (1).

Inside those threads, loop, pulling a job from the queue and processing
it. Return when the queue is empty

Inside the main routine, meanwhile, just call join() on each
thread object. When all thread are joined you are done.

There's no point in continually creating and destroying threads
(which is expensive), since you only and always ever only need 2.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at