14 #include <boost/asio/io_context.hpp> 15 #include <boost/asio/post.hpp> 19 #include <type_traits> 40 template <typename FunctorT, typename ResultT = typename std::result_of<FunctorT()>::type>
42 auto task = std::packaged_task<ResultT()>(std::forward<FunctorT>(functor));
43 auto future = task.get_future();
57 AsyncRun(std::thread::hardware_concurrency());
void AsyncRun()
Launch threads to run tasks asynchronously.
~ThreadPool()
Stops the ThreadPool and joins all its threads.
std::future< ResultT > Post(FunctorT &&functor)
Post a task to the pool.
This file contains definitions of common data structures used in traffic manager. ...
void CreateThreads(size_t count, F functor)
void Run()
Run tasks in this thread.
boost::asio::io_context::work _work_to_do
void RunFor(time_duration duration)
Run tasks in this thread for an specific duration.
A thread pool based on Boost.Asio's io context.
boost::asio::io_context _io_context
void Stop()
Stop the ThreadPool and join all its threads.
auto MoveHandler(FunctorT &&func)
Hack to trick asio into accepting move-only handlers, if the handler were actually copied it would re...
Positive time duration up to milliseconds resolution.
void AsyncRun(size_t worker_threads)
Launch threads to run tasks asynchronously.
constexpr auto to_chrono() const
Inherit (privately) to suppress copy/move construction and assignment.
auto & io_context()
Return the underlying io_context.