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

typedef threads::policies::callback_notifier notification_policy_type#
typedef std::unique_ptr<thread_pool_base> pool_type#
typedef threads::policies::scheduler_base scheduler_type#
typedef std::vector<pool_type> pool_vector#

Public Functions

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

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

thread_pool_base &default_pool() const#
scheduler_type &default_scheduler() 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)#

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
  • func – [in] The function or function object to execute as the thread’s function. This must have a signature as defined by thread_function_type.

  • description – [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.

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

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
  • func – [in] The function or function object to execute as the thread’s function. This must have a signature as defined by thread_function_type.

  • 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.

  • description – [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.

bool run()#

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)#

Forcefully stop the thread-manager.

Parameters

blocking

bool is_busy()#
bool is_idle()#
void wait()#
void suspend()#
void resume()#
inline 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 = std::size_t(-1), bool reset = false)#

return the number of HPX-threads with the given state

Note

This function lock the internal OS lock in the thread manager

std::int64_t get_idle_core_count()#
mask_type get_idle_core_mask()#
std::int64_t get_background_thread_count()#
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()#
bool cleanup_terminated(bool delete_all)#
inline 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.

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

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.).

inline mask_type get_used_processing_units() const#

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

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

Private Types

typedef std::mutex mutex_type#

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_#