Boost logo

Boost Users :

Subject: Re: [Boost-users] Create A Boost Thread for each HW Thread?
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2011-06-09 22:19:24


On Thu, Jun 9, 2011 at 18:13, Brad <boost_at_[hidden]> wrote:
> What's the proper way to start a boost thread for each hardware thread
> available? I can do this... but it is clunky and does not scale
> (especially when there are lots of cores):
>

Sound like you want a thread_group, to which you can call
create_thread() or add_thread() in a loop then join_all():
<http://www.boost.org/doc/html/thread/thread_management.html#thread.thread_management.threadgroup>

~ Scott

Or you could always do silly things with recursion:
    void foo(int n = boost::thread::hardware_concurrency()) {
        if (n < 1) return;
        boost::thread bar( task, thread_data, St );
        foo(n-1);
        bar.join();
    }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net