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

thread_data *get_self_id_data()#

The function get_self_id_data returns the data of the HPX thread id associated with the current thread (or nullptr if the current thread is not a HPX thread).

thread_data *get_thread_id_data(thread_id_ref_type const &tid)#
thread_data *get_thread_id_data(thread_id_type const &tid)#
thread_self &get_self()#

The function get_self returns a reference to the (OS thread specific) self reference to the current HPX thread.

thread_self *get_self_ptr()

The function get_self_ptr returns a pointer to the (OS thread specific) self reference to the current HPX thread.

thread_self_impl_type *get_ctx_ptr()#

The function get_ctx_ptr returns a pointer to the internal data associated with each coroutine.

thread_self *get_self_ptr_checked(error_code &ec = throws)#

The function get_self_ptr_checked returns a pointer to the (OS thread specific) self reference to the current HPX thread.

thread_id_type get_self_id()

The function get_self_id returns the HPX thread id of the current thread (or zero if the current thread is not a HPX thread).

thread_id_type get_parent_id()#

The function get_parent_id returns the HPX thread id of the current thread’s parent (or zero if the current thread is not a HPX thread).

Note

This function will return a meaningful value only if the code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE being defined.

std::size_t get_parent_phase()#

The function get_parent_phase returns the HPX phase of the current thread’s parent (or zero if the current thread is not a HPX thread).

Note

This function will return a meaningful value only if the code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE being defined.

std::ptrdiff_t get_self_stacksize()#

The function get_self_stacksize returns the stack size of the current thread (or zero if the current thread is not a HPX thread).

thread_stacksize get_self_stacksize_enum()#

The function get_self_stacksize_enum returns the stack size of the /.

std::uint32_t get_parent_locality_id()#

The function get_parent_locality_id returns the id of the locality of the current thread’s parent (or zero if the current thread is not a HPX thread).

Note

This function will return a meaningful value only if the code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE being defined.

std::uint64_t get_self_component_id()#

The function get_self_component_id returns the lva of the component the current thread is acting on

Note

This function will return a meaningful value only if the code was compiled with HPX_HAVE_THREAD_TARGET_ADDRESS being defined.

class thread_data : public thread_data_reference_counting#
#include <thread_data.hpp>

A thread is the representation of a ParalleX thread. It’s a first class object in ParalleX. 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 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 state, thread_restart_state state_ex = thread_restart_state::unknown, std::memory_order load_order = std::memory_order_acquire, std::memory_order exchange_order = std::memory_order_seq_cst) 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 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

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

inline bool set_state_tagged(thread_schedule_state newstate, thread_state &prev_state, thread_state &new_tagged_state, std::memory_order exchange_order = std::memory_order_seq_cst) noexcept#
inline bool restore_state(thread_state new_state, thread_state old_state, std::memory_order load_order = std::memory_order_relaxed, std::memory_order load_exchange = std::memory_order_seq_cst) 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
  • newstate – [in] The new state to be set for the thread.

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

Returns

This function returns true if the state has been changed successfully

inline bool restore_state(thread_schedule_state new_state, thread_restart_state state_ex, thread_state old_state, std::memory_order load_exchange = std::memory_order_seq_cst) noexcept#
inline constexpr std::uint64_t get_component_id() const noexcept#

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

inline util::thread_description get_description() const#
inline util::thread_description set_description(util::thread_description)#
inline util::thread_description get_lco_description() const#
inline util::thread_description set_lco_description(util::thread_description)#
inline constexpr std::uint32_t get_parent_locality_id() const noexcept#

Return the locality of the parent thread.

inline constexpr thread_id_type get_parent_thread_id() const noexcept#

Return the thread id of the parent thread.

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

Return the phase of the parent thread.

inline constexpr util::backtrace const *get_backtrace() const noexcept#
inline util::backtrace const *set_backtrace(util::backtrace 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 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 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#

Protected Functions

inline thread_restart_state set_state_ex(thread_restart_state new_state) 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

newstate – [in] The new extended state to be set for the thread.

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