diff --git a/asio/include/asio/io_context.hpp b/asio/include/asio/io_context.hpp index 73212f197b..6f1c0b47f2 100644 --- a/asio/include/asio/io_context.hpp +++ b/asio/include/asio/io_context.hpp @@ -118,6 +118,35 @@ namespace detail { * } * @endcode * + * @par Submitting arbitrary tasks to the io_context + * + * To submit functions to the io_context, use the @ref asio::dispatch, + * @ref asio::post or @ref asio::defer free functions. + * + * For example: + * + * @code void my_task() + * { + * ... + * } + * + * ... + * + * asio::io_context io_context; + * + * // Submit a function to the io_context. + * asio::post(io_context, my_task); + * + * // Submit a lambda object to the io_context. + * asio::post(io_context, + * []() + * { + * ... + * }); + * + * // Run the io_context until it runs out of work. + * io_context.run(); @endcode + * * @par Stopping the io_context from running out of work * * Some applications may need to prevent an io_context object's run() call from diff --git a/asio/include/asio/thread_pool.hpp b/asio/include/asio/thread_pool.hpp index ae915b3ec7..f12126a801 100644 --- a/asio/include/asio/thread_pool.hpp +++ b/asio/include/asio/thread_pool.hpp @@ -29,6 +29,36 @@ namespace asio { /** * The thread pool class is an execution context where functions are permitted * to run on one of a fixed number of threads. + * + * @par Submitting tasks to the pool + * + * To submit functions to the io_context, use the @ref asio::dispatch, + * @ref asio::post or @ref asio::defer free functions. + * + * For example: + * + * @code void my_task() + * { + * ... + * } + * + * ... + * + * // Launch the pool with four threads. + * asio::thread_pool pool(4); + * + * // Submit a function to the pool. + * asio::post(pool, my_task); + * + * // Submit a lambda object to the pool. + * asio::post(pool, + * []() + * { + * ... + * }); + * + * // Wait for all tasks in the pool to complete. + * pool.join(); @endcode */ class thread_pool : public execution_context