threadmanager

The contents of this module can be included with the header hpx/modules/threadmanager.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/threadmanager.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 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 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
void 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_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.

Return

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()
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(util::function_nonser<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)
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)

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(const std::string &pool_name) const
void set_scheduler_mode(threads::policies::scheduler_mode mode)
void add_scheduler_mode(threads::policies::scheduler_mode mode)
void add_remove_scheduler_mode(threads::policies::scheduler_mode to_add_mode, threads::policies::scheduler_mode to_remove_mode)
void remove_scheduler_mode(threads::policies::scheduler_mode mode)
void reset_thread_distribution()
void init_tss(std::size_t global_thread_num)
void deinit_tss()
std::int64_t get_queue_length(bool reset)
std::int64_t get_cumulative_duration(bool reset)
std::int64_t get_thread_count_unknown(bool reset)
std::int64_t get_thread_count_active(bool reset)
std::int64_t get_thread_count_pending(bool reset)
std::int64_t get_thread_count_suspended(bool reset)
std::int64_t get_thread_count_terminated(bool reset)
std::int64_t get_thread_count_staged(bool reset)

Private Types

typedef std::mutex mutex_type

Private Members

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_