hpx/threading_base/thread_data.hpp#

Defined in header hpx/threading_base/thread_data.hpp.

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

namespace hpx
namespace threads

Functions

constexpr thread_data *get_thread_id_data(thread_id_ref_type const &tid) noexcept#
constexpr thread_data *get_thread_id_data(thread_id_type const &tid) noexcept#
class thread_data : public thread_data_reference_counting#
#include <thread_data.hpp>

A thread is the representation of a HPX thread. It’s a first class object in HPX. In our implementation this is a user level thread running on top of one of the OS threads spawned by the thread-manager.

A thread encapsulates:

  • A thread status word (see the functions thread::get_state and thread::set_state)

  • A function to execute (the thread function)

  • A frame (in this implementation this is a block of memory used as the threads stack)

  • A block of registers (not implemented yet)

Generally, threads are not created or executed directly. All functionality related to the management of threads is implemented by the thread-manager.

Public Types

using spinlock_pool = util::spinlock_pool<thread_data>#

Public Functions

thread_data(thread_data const&) = delete#
thread_data(thread_data&&) = delete#
thread_data &operator=(thread_data const&) = delete#
thread_data &operator=(thread_data&&) = delete#
inline thread_state get_state(std::memory_order const order = std::memory_order_acquire) const noexcept#

The get_state function queries the state of this thread instance.

Note

This function will be seldom used directly. Most of the time the state of a thread will be retrieved by using the function threadmanager::get_state.

Returns

This function returns the current state of this thread. It will return one of the values as defined by the thread_state enumeration.

inline thread_state set_state(thread_schedule_state const state, thread_restart_state state_ex = thread_restart_state::unknown, std::memory_order const load_order = std::memory_order_acquire, std::memory_order const exchange_order = std::memory_order_acq_rel) const noexcept#

The set_state function changes the state of this thread instance.

Note

This function will be seldom used directly. Most of the time the state of a thread will have to be changed using the thread-manager. Moreover, changing the thread state using this function does not change its scheduling status. It only sets the thread’s status word. To change the thread’s scheduling status threadmanager::set_state should be used.

Parameters
  • state – [in] The new state to be set for the thread.

  • state_ex – [in]

  • load_order – [in]

  • exchange_order – [in]

inline bool set_state_tagged(thread_schedule_state const newstate, thread_state const &prev_state, thread_state &new_tagged_state, std::memory_order exchange_order = std::memory_order_acq_rel) const noexcept#
inline bool restore_state(thread_state const new_state, thread_state const old_state, std::memory_order const load_order = std::memory_order_relaxed, std::memory_order const load_exchange = std::memory_order_acq_rel) const noexcept#

The restore_state function changes the state of this thread instance depending on its current state. It will change the state atomically only if the current state is still the same as passed as the second parameter. Otherwise it won’t touch the thread state of this instance.

Note

This function will be seldom used directly. Most of the time the state of a thread will have to be changed using the threadmanager. Moreover, changing the thread state using this function does not change its scheduling status. It only sets the thread’s status word. To change the thread’s scheduling status threadmanager::set_state should be used.

Parameters
  • new_state – [in] The new state to be set for the thread.

  • old_state – [in] The old state of the thread which still has to be the current state.

  • load_order – [in]

  • load_exchange – [in]

Returns

This function returns true if the state has been changed successfully

inline bool restore_state(thread_schedule_state new_state, thread_restart_state const state_ex, thread_state old_state, std::memory_order const load_exchange = std::memory_order_acq_rel) const noexcept#
inline constexpr thread_priority get_priority() const noexcept#
inline void set_priority(thread_priority priority) noexcept#
inline bool interruption_requested() const noexcept#
inline bool interruption_enabled() const noexcept#
inline bool set_interruption_enabled(bool enable) noexcept#
inline void interrupt(bool flag = true)#
bool interruption_point(bool throw_on_interrupt = true)#
bool add_thread_exit_callback(function<void()> const &f)#
void run_thread_exit_callbacks()#
void free_thread_exit_callbacks()#
inline bool runs_as_child(std::memory_order mo = std::memory_order_acquire) const noexcept#
inline constexpr bool is_stackless() const noexcept#
void destroy_thread() override#
inline constexpr policies::scheduler_base *get_scheduler_base() const noexcept#
inline constexpr std::size_t get_last_worker_thread_num() const noexcept#
inline void set_last_worker_thread_num(std::size_t last_worker_thread_num) noexcept#
inline constexpr std::ptrdiff_t get_stack_size() const noexcept#
inline thread_stacksize get_stack_size_enum() const noexcept#
template<typename ThreadQueue>
inline constexpr ThreadQueue &get_queue() noexcept#
inline coroutine_type::result_type operator()(hpx::execution_base::this_thread::detail::agent_storage *agent_storage)#

Execute the thread function.

Returns

This function returns the thread state the thread should be scheduled from this point on. The thread manager will use the returned value to set the thread’s scheduling status.

inline coroutine_type::result_type invoke_directly()#

Directly execute the thread function (inline)

Returns

This function returns the thread state the thread should be scheduled from this point on. The thread manager will use the returned value to set the thread’s scheduling status.

inline virtual thread_id_type get_thread_id() const#
inline virtual std::size_t get_thread_phase() const noexcept#
virtual std::size_t get_thread_data() const = 0#
virtual std::size_t set_thread_data(std::size_t data) = 0#
virtual void init() = 0#
virtual void rebind(thread_init_data &init_data) = 0#
thread_data(thread_init_data &init_data, void *queue, std::ptrdiff_t stacksize, bool is_stackless = false, thread_id_addref addref = thread_id_addref::yes)#
virtual ~thread_data() override#
virtual void destroy() noexcept = 0#

Public Static Functions

static inline constexpr std::uint64_t get_component_id() noexcept#

Return the id of the component this thread is running in.

static inline constexpr threads::thread_description get_description() noexcept#
static inline constexpr threads::thread_description set_description(threads::thread_description) noexcept#
static inline constexpr threads::thread_description get_lco_description() noexcept#
static inline constexpr threads::thread_description set_lco_description(threads::thread_description) noexcept#
static inline constexpr std::uint32_t get_parent_locality_id() noexcept#

Return the locality of the parent thread.

static inline constexpr thread_id_type get_parent_thread_id() noexcept#

Return the thread id of the parent thread.

static inline constexpr std::size_t get_parent_thread_phase() noexcept#

Return the phase of the parent thread.

static inline constexpr util::backtrace const *get_backtrace() noexcept#
static inline constexpr util::backtrace const *set_backtrace(util::backtrace const*) noexcept#

Protected Functions

inline thread_restart_state set_state_ex(thread_restart_state const new_state, std::memory_order const load_order = std::memory_order_acquire, std::memory_order const load_exchange = std::memory_order_acq_rel) const noexcept#

The set_state function changes the extended state of this thread instance.

Note

This function will be seldom used directly. Most of the time the state of a thread will have to be changed using the threadmanager.

Parameters
  • new_state – [in] The new extended state to be set for the thread.

  • load_order – [in]

  • load_exchange – [in]

void rebind_base(thread_init_data &init_data)#

Private Members

mutable std::atomic<thread_state> current_state_#
thread_priority priority_#
bool requested_interrupt_#
bool enabled_interrupt_#
bool ran_exit_funcs_#
const bool is_stackless_#
std::atomic<bool> runs_as_child_#
std::forward_list<hpx::function<void()>> exit_funcs_#
policies::scheduler_base *scheduler_base_#
std::size_t last_worker_thread_num_#
std::ptrdiff_t stacksize_#
thread_stacksize stacksize_enum_#
void *queue_#