Boost logo

Boost Users :

Subject: [Boost-users] Create A Boost Thread for each HW Thread?
From: Brad (boost_at_[hidden])
Date: 2011-06-09 21:13:02


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):

const unsigned int hwt()
{
          const unsigned int t = boost::thread::hardware_concurrency();
          return t;
}

if ( t == 2 )
{
          boost::thread _01( task, thread_data, St );
          boost::thread _02( task, thread_data, St );

          _01.join();
          _02.join();
}

if ( t == 4 )
{
          boost::thread _01( task, thread_data, St );
          boost::thread _02( task, thread_data, St );
          boost::thread _03( task, thread_data, St );
          boost::thread _04( task, thread_data, St );

          _01.join();
          _02.join();
          _03.join();
          _04.join();
}

It seems that a for loop (or something similar) could be used to start
the same number of boost threads as there are HWTs.

Could someone point me in the right direction?

Thanks,

Brad


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