You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've simplified the enqueue method, now the additional classes are not needed and the container is std::deque<std::function<void()>>:
template<classResult, classCallable>
std::future<Result> ThreadPoolManager::enqueue(Callable callable) {
/** * Create task, we use RAII here and copy-capture lambda later as this std::packed_task has to be * deleted after it was executed.*/auto task = std::make_shared<std::packaged_task<Result()>>(callable);
/** Get the result of the task */
std::future<Result> result = task->get_future();
{
/** Lock the queue */
std::unique_lock<Mutex> lock(mutex_);
/** Push new task to the queue */
tasks_.push_back([=] {
/** Execute task */
(*task)();
});
}
/** Notify one worker that there is a work to do */
conditional_variable_.notify_one();
return result;
}
Activity
progschj commentedon Feb 16, 2013
I like this. If only there was a way to move-capture then one could even avoid the shared_ptr.
ltwardus commentedon Feb 17, 2013
Well, i was messing with something like:
, but with no luck and at the moment it already looks too weird and in my opinion is complicating things more than it's needed :)
Simplifications and fixes