C++ Boost中的线程数组

and*_*rey 2 c++ multithreading boost stdthread

我正在尝试使用线程创建一个数组.我的代码看起来像这样:

boost::thread threads[10];

   for(int i = 0; i < 10; i++){
         client c(io_services[i], "www.boost.org", "/");

         threads[i] ( boost::bind(workerFunc, i) );

  }
Run Code Online (Sandbox Code Playgroud)

我收到编译错误:

error: no match for call to ‘(boost::thread) (boost::_bi::bind_t<void, void (*)(int), boost::_bi::list1<boost::_bi::value<int> > >)’
       threads[i] ( boost::bind(workerFunc, i) );
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚我的代码中需要更改的内容.任何帮助将不胜感激.

And*_*ndy 6

您正在寻找:

boost::thread threads[10];

for(int i = 0; i < 10; i++){
    client c(io_services[i], "www.boost.org", "/");

    threads[i] = boost::thread( boost::bind(workerFunc, i) );
}
Run Code Online (Sandbox Code Playgroud)