我想修改此线程池实现http://roar11.com/2016/01/a-platform-independent-thread-pool-using-c14/以删除将来的返回。我的函数不需要返回任何内容,但我无法修改提交函数来执行此操作。
template <class Func, class... Args>
void submit(Func &&func, Args &&... args)
{
auto boundTask = std::bind(std::forward<Func>(func),
std::forward<Args>(args)...);
m_workQueue.push(std::make_unique<ThreadTask<decltype(boundTask)>>(std::move(boundTask)));
}
我这样使用它
pool_.submit([](int i){std::cout << i << std::endl;}, 1);
但它给了我以下错误
./include/concurrency/ThreadPool.h: In instantiation of ‘bool
conc::ThreadPool::submit(Func&&, Args&& ...) [with Func =
zia::ZiaServer::startService()::<lambda(int)>; Args = {int}]’:
src/ZiaServer.cpp:16:65: required from here
./include/concurrency/ThreadPool.h:85:9: error: cannot bind non-const
lvalue reference of type ‘std::unique_ptr<conc::IThreadTask>&’ to an
rvalue of type ‘std::unique_ptr<conc::IThreadTask>’
tasks_.push(std::make_unique<ThreadTask<decltype(boundTask)>>
(std::move(boundTask)));
知道发生了什么事吗?