io_service

The contents of this module can be included with the header hpx/modules/io_service.hpp. These headers may be used by user-code but are not guaranteed stable (neither header location nor contents). You are using these at your own risk. If you wish to use non-public functionality from a module we strongly suggest only including the module header hpx/modules/io_service.hpp, not the particular header in which the functionality you would like to use is defined. See Public API for a list of names that are part of the public HPX API.

namespace hpx
namespace util
class io_service_pool
#include <io_service_pool.hpp>

A pool of io_service objects.

Public Functions

HPX_NON_COPYABLE(io_service_pool)
io_service_pool(std::size_t pool_size = 2, threads::policies::callback_notifier const &notifier = threads::policies::callback_notifier(), char const *pool_name = "", char const *name_postfix = "")

Construct the io_service pool.

Parameters
  • pool_size: [in] The number of threads to run to serve incoming requests

  • start_thread: [in]

io_service_pool(threads::policies::callback_notifier const &notifier, char const *pool_name = "", char const *name_postfix = "")

Construct the io_service pool.

Parameters
  • start_thread: [in]

~io_service_pool()
bool run(bool join_threads = true, barrier *startup = nullptr)

Run all io_service objects in the pool. If join_threads is true this will also wait for all threads to complete

bool run(std::size_t num_threads, bool join_threads = true, barrier *startup = nullptr)

Run all io_service objects in the pool. If join_threads is true this will also wait for all threads to complete

void stop()

Stop all io_service objects in the pool.

void join()

Join all io_service threads in the pool.

void clear()

Clear all internal data structures.

void wait()

Wait for all work to be done.

bool stopped()
asio::io_context &get_io_service(int index = -1)

Get an io_service to use.

std::thread &get_os_thread_handle(std::size_t thread_num)

access underlying thread handle

std::size_t size() const

Get number of threads associated with this I/O service.

void thread_run(std::size_t index, barrier *startup = nullptr)

Activate the thread index for this thread pool.

char const *get_name() const

Return name of this pool.

Protected Functions

bool run_locked(std::size_t num_threads, bool join_threads, barrier *startup)
void stop_locked()
void join_locked()
void clear_locked()
void wait_locked()

Private Types

using io_service_ptr = std::unique_ptr<asio::io_context>
using work_type = asio::io_context::work

Private Functions

work_type initialize_work(asio::io_context &io_service)

Private Members

std::mutex mtx_
std::vector<io_service_ptr> io_services_

The pool of io_services.

std::vector<std::thread> threads_
std::vector<work_type> work_

The work that keeps the io_services running.

std::size_t next_io_service_

The next io_service to use for a connection.

bool stopped_

set to true if stopped

std::size_t pool_size_

initial number of OS threads to execute in this pool

threads::policies::callback_notifier const &notifier_

call this for each thread start/stop

char const *pool_name_
char const *pool_name_postfix_
bool waiting_

Set to true if waiting for work to finish.

barrier wait_barrier_
barrier continue_barrier_