这是前一个问题(这里)的后续内容,但我正在研究一个多线程应用程序,我想将一个Boost packaged_task发布到一个线程化的io_service.我坚持使用C++ 03编译器(所以std :: move已经出局),并且packaged_task不可复制.我已经尝试将它包装在shared_ptr中并传递它以及许多其他内容.这是我当前的尝试和后续的编译器错误.知道如何让这个工作吗?
boost::asio::io_service io_service;
boost::thread_group threads;
boost::asio::io_service::work work(io_service);
for (int i = 0; i < maxNumThreads; ++i)
{
threads.create_thread(boost::bind(&boost::asio::io_service::run,
&io_service));
}
std::vector<boost::shared_future<bool> > pending_data; // vector of futures
bool process_data(int,int){...}
...
for(int theTime = 0; theTime != totalScenarioTime; ++theTime)
{
for(int i = 0; i < numSmallTasks; ++i)
{
boost::packaged_task<bool> task(boost::bind(&process_data,i,theTime));
boost::shared_future<bool> fut(task.get_future());
pending_data.push_back(fut); // C++11 possible: (std::move(fut) when fut is a unique_future);
io_service.post(task); // C++11 possible: (std::move(task));
}
// After loop - wait until …Run Code Online (Sandbox Code Playgroud)