std::future<typename std::result_of<TFunction()>::type> submit(TFunction&& func) { typedef typename std::result_of<TFunction()>::type result_type; std::packaged_task<result_type()> task(std::forward<TFunction>(func)); std::future<result_type> future_result(task.get_future()); m_work_queue.push(std::move(task)); return future_result; }
inline void add_to_queue(osmium::thread::Queue<std::future<T>>& queue, std::exception_ptr&& exception) { std::promise<T> promise; queue.push(promise.get_future()); promise.set_exception(std::move(exception)); }
void shutdown_all_workers() { for (int i = 0; i < m_num_threads; ++i) { // The special function wrapper makes a worker shut down. m_work_queue.push(function_wrapper{0}); } }
inline void add_to_queue(osmium::thread::Queue<std::future<T>>& queue, T&& data) { std::promise<T> promise; queue.push(promise.get_future()); promise.set_value(std::forward<T>(data)); }