Search code examples
c++multithreadingbooststdthread

Array of threads in C++ Boost


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.


Solution

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