类似线程池,demo如下:
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>
void fun(int i) {
std::cout << "fun:" << i << std::endl;
}
int main() {
boost::thread_group threads;
for (auto i = 0;i < 10;i++) {
threads.create_thread(boost::bind(fun, i));
}
threads.join_all();
return 0;
}