threadmanager¶
#include <compatibility/hpx/runtime/threads/threadmanager.hpp>
¶
#include <hpx/threadmanager.hpp>
¶
-
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 std::unique_ptr<thread_pool_base>
pool_type
¶
Public Functions
-
threadmanager
(notification_policy_type ¬ifier, detail::network_background_callback_type network_background_callback = detail::network_background_callback_type())¶
-
~threadmanager
()¶
-
void
init
()¶
-
void
create_pools
()¶
-
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¶
-
void
register_work
(thread_init_data &data, thread_state_enum initial_state = pending, 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.initial_state
: [in] The value of this parameter defines the initial state of the newly created thread. This must be one of the values as defined by the thread_state enumeration (thread_state::pending, or thread_state::suspended, any other value will throw a hpx::bad_parameter exception).
-
void
register_thread
(thread_init_data &data, thread_id_type &id, thread_state_enum initial_state = pending, bool run_now = true, 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.initial_state
: [in] The value of this parameter defines the initial state of the newly created thread. This must be one of the values as defined by the thread_state enumeration (thread_state::pending, or thread_state::suspended, any other value will throw a hpx::bad_parameter exception).run_now
: [in] If this parameter is true and the initial state is given as thread_state::pending the thread will be run immediately, otherwise it will be scheduled to run later (either this function is called for another thread using true for the parameter run_now or the function threadmanager::do_some_work is called). This parameter is optional and defaults to true.
-
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
:
-
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_state_enum 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
-
bool
enumerate_threads
(util::function_nonser<bool(thread_id_type)> const &f, thread_state_enum 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.
-
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.
-
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
deinit_tss
()¶
Private Members
-
mutex_type
mtx_
¶
-
pool_vector
pools_
¶
-
notification_policy_type &
notifier_
¶
-
detail::network_background_callback_type
network_background_callback_
¶
-
typedef std::unique_ptr<thread_pool_base>
-
class
-
namespace