c++ Boost中的线程数组

时间:2022-03-22 19:33:22

I am trying to create an array with threads. My code looks like this:

我正在尝试用线程创建一个数组。我的代码是这样的:

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

  }

And I am getting compilation error:

我得到了编译错误:

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

I can not figure out what I need change in my code. Any help will be appreciated.

我不知道我的代码中需要修改什么。如有任何帮助,我们将不胜感激。

1 个解决方案

#1


5  

You're looking for:

你在寻找:

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) );
}

#1


5  

You're looking for:

你在寻找:

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) );
}