On 7/26/2010 11:10 AM, Internet Retard wrote:
1. Get the number of cores using boost::thread::hardware_concurrency()
Correct.
2. Fill a std::queue container with jobs for the threads.
Correct.
3. While the container is not empty and there are less
active threads than boost::thread::hardware_concurrency(), then start a
new thread.
Incorrect.
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.