hpx/modules/threadmanager.hpp#

Defined in header hpx/modules/threadmanager.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace threads
class threadmanager#
#include <threadmanager.hpp>

The thread-manager class is the central instance of management for all (non-depleted) threads

Public Types

using notification_policy_type = threads::policies::callback_notifier#
using pool_type = std::unique_ptr<thread_pool_base>#
using pool_vector = std::vector<pool_type>#

Public Functions

threadmanager(hpx::util::runtime_configuration &rtcfg_, notification_policy_type &notifier, detail::network_background_callback_type const &network_background_callback = detail::network_background_callback_type())#
threadmanager(threadmanager const&) = delete#
threadmanager(threadmanager&&) = delete#
threadmanager &operator=(threadmanager const&) = delete#
threadmanager &operator=(threadmanager&&) = delete#
~threadmanager()#
void init() const#
void create_pools()#
void print_pools(std::ostream&) const#

FIXME move to private and add &#8212;hpx:printpools cmd line option.

thread_pool_base &default_pool() const#
thread_pool_base &get_pool(std::string const &pool_name) const#
thread_pool_base &get_pool(pool_id_type const &pool_id) const#
thread_pool_base &get_pool(std::size_t thread_index) const#
bool pool_exists(std::string const &pool_name) const#
bool pool_exists(std::size_t pool_index) const#
thread_id_ref_type register_work(thread_init_data &data, error_code &ec = throws) const#

The function register_work adds a new work item to the thread manager. It doesn’t immediately create a new thread, it just adds the task parameters (function, initial state and description) to the internal management data structures. The thread itself will be created when the number of existing threads drops below the number of threads specified by the constructors max_count parameter.

Parameters
  • data – [in] The value of this parameter allows to specify a description of the thread to create. This information is used for logging purposes mainly, but might be useful for debugging as well. This parameter is optional and defaults to an empty string.

  • ec

void register_thread(thread_init_data &data, thread_id_ref_type &id, error_code &ec = throws) const#

The function register_thread adds a new work item to the thread manager. It creates a new thread, adds it to the internal management data structures, and schedules the new thread, if appropriate.

Parameters
  • data – [in] The value of this parameter allows to specify a description of the thread to create. This information is used for logging purposes mainly, but might be useful for debugging as well. This parameter is optional and defaults to an empty string.

  • id – [out] This parameter will hold the id of the created thread. This id is guaranteed to be validly initialized before the thread function is executed.

  • ec

bool run() const#

Run the thread manager’s work queue. This function instantiates the specified number of OS threads in each pool. All OS threads are started to execute the function tfunc.

Returns

The function returns true if the thread manager has been started successfully, otherwise it returns false.

void stop(bool blocking = true) const#

Forcefully stop the thread-manager.

Parameters

blocking

bool is_busy() const#
bool is_idle() const#
void wait() const#
bool wait_for(hpx::chrono::steady_duration const &rel_time) const#
void suspend() const#
void resume() const#
hpx::state status() const#

Return whether the thread manager is still running This returns the “minimal state”, i.e. the state of the least advanced thread pool

std::int64_t get_thread_count(thread_schedule_state state = thread_schedule_state::unknown, thread_priority priority = thread_priority::default_, std::size_t num_thread = static_cast<std::size_t>(-1), bool reset = false) const#

return the number of HPX-threads with the given state

Note

This function locks the internal OS lock in the thread manager

std::int64_t get_idle_core_count() const#
mask_type get_idle_core_mask() const#
std::int64_t get_background_thread_count() const#
bool enumerate_threads(hpx::function<bool(thread_id_type)> const &f, thread_schedule_state state = thread_schedule_state::unknown) const#
void abort_all_suspended_threads() const#
bool cleanup_terminated(bool delete_all) const#
std::size_t get_os_thread_count() const#

Return the number of OS threads running in this thread-manager.

This function will return correct results only if the thread-manager is running.

std::thread &get_os_thread_handle(std::size_t num_thread) const#
void report_error(std::size_t num_thread, std::exception_ptr const &e) const#

API functions forwarding to notification policy.

This notifies the thread manager that the passed exception has been raised. The exception will be routed through the notifier and the scheduler (which will result in it being passed to the runtime object, which in turn will report it to the console, etc.).

mask_type get_used_processing_units() const#

Returns the mask identifying all processing units used by this thread manager.

hwloc_bitmap_ptr get_pool_numa_bitmap(std::string const &pool_name) const#
void set_scheduler_mode(threads::policies::scheduler_mode mode) const noexcept#
void add_scheduler_mode(threads::policies::scheduler_mode mode) const noexcept#
void add_remove_scheduler_mode(threads::policies::scheduler_mode to_add_mode, threads::policies::scheduler_mode to_remove_mode) const noexcept#
void remove_scheduler_mode(threads::policies::scheduler_mode mode) const noexcept#
void reset_thread_distribution() const noexcept#
std::int64_t get_queue_length(bool reset) const#
std::int64_t get_cumulative_duration(bool reset) const#
std::int64_t get_thread_count_unknown(bool reset) const#
std::int64_t get_thread_count_active(bool reset) const#
std::int64_t get_thread_count_pending(bool reset) const#
std::int64_t get_thread_count_suspended(bool reset) const#
std::int64_t get_thread_count_terminated(bool reset) const#
std::int64_t get_thread_count_staged(bool reset) const#

Public Static Functions

static void init_tss(std::size_t global_thread_num)#
static void deinit_tss()#

Private Types

using mutex_type = std::mutex#

Private Functions

policies::thread_queue_init_parameters get_init_parameters() const#
void create_scheduler_user_defined(hpx::resource::scheduler_function const&, thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&)#
void create_scheduler_local(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_local_priority_fifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_local_priority_lifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_static(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_static_priority(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_abp_priority_fifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_abp_priority_lifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_shared_priority(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_local_workrequesting_fifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_local_workrequesting_lifo(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#
void create_scheduler_local_workrequesting_mc(thread_pool_init_parameters const&, policies::thread_queue_init_parameters const&, std::size_t)#

Private Members

mutable mutex_type mtx_#
hpx::util::runtime_configuration &rtcfg_#
std::vector<pool_id_type> threads_lookup_#
pool_vector pools_#
notification_policy_type &notifier_#
detail::network_background_callback_type network_background_callback_#