hpx/schedulers/thread_queue.hpp

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

namespace hpx
namespace threads
namespace policies
template<typename Mutex, typename PendingQueuing, typename StagedQueuing, typename TerminatedQueuing>
class thread_queue

Public Functions

bool cleanup_terminated_locked(bool delete_all = false)

This function makes sure all threads which are marked for deletion (state is terminated) are properly destroyed.

This returns ‘true’ if there are no more terminated threads waiting to be deleted.

bool cleanup_terminated(bool delete_all = false)
thread_queue(std::size_t queue_num = std::size_t(-1), thread_queue_init_parameters parameters = {})
~thread_queue()
std::int64_t get_queue_length(std::memory_order order = std::memory_order_acquire) const
std::int64_t get_pending_queue_length(std::memory_order order = std::memory_order_acquire) const
std::int64_t get_staged_queue_length(std::memory_order order = std::memory_order_acquire) const
constexpr void increment_num_pending_misses(std::size_t = 1)
constexpr void increment_num_pending_accesses(std::size_t = 1)
constexpr void increment_num_stolen_from_pending(std::size_t = 1)
constexpr void increment_num_stolen_from_staged(std::size_t = 1)
constexpr void increment_num_stolen_to_pending(std::size_t = 1)
constexpr void increment_num_stolen_to_staged(std::size_t = 1)
void create_thread(thread_init_data &data, thread_id_ref_type *id, error_code &ec)
void move_work_items_from(thread_queue *src, std::int64_t count)
void move_task_items_from(thread_queue *src, std::int64_t count)
bool get_next_thread(threads::thread_id_ref_type &thrd, bool allow_stealing = false, bool steal = false)

Return the next thread to be executed, return false if none is available

void schedule_thread(threads::thread_id_ref_type thrd, bool other_end = false)

Schedule the passed thread.

void destroy_thread(threads::thread_data *thrd)

Destroy the passed thread as it has been terminated.

std::int64_t get_thread_count(thread_schedule_state state = thread_schedule_state::unknown) const

Return the number of existing threads with the given state.

void abort_all_suspended_threads()
bool enumerate_threads(hpx::function<bool(thread_id_type)> const &f, thread_schedule_state state = thread_schedule_state::unknown, ) const
bool wait_or_add_new(bool, std::size_t &added, bool steal = false)

This is a function which gets called periodically by the thread manager to allow for maintenance tasks to be executed in the scheduler. Returns true if the OS thread calling this function has to be terminated (i.e. no more work has to be done).

bool wait_or_add_new(bool running, std::size_t &added, thread_queue *addfrom, bool steal = false)
bool dump_suspended_threads(std::size_t num_thread, std::int64_t &idle_loop_count, bool running)
void on_start_thread(std::size_t)
void on_stop_thread(std::size_t)
void on_error(std::size_t, std::exception_ptr const&)

Public Static Functions

static void deallocate(threads::thread_data *p)

Protected Functions

template<typename Lock>
void create_thread_object(threads::thread_id_ref_type &thrd, threads::thread_init_data &data, Lock &lk)
std::size_t add_new(std::int64_t add_count, thread_queue *addfrom, std::unique_lock<mutex_type> &lk, bool steal = false)
bool add_new_always(std::size_t &added, thread_queue *addfrom, std::unique_lock<mutex_type> &lk, bool steal = false)
void recycle_thread(thread_id_type thrd)

Protected Static Attributes

util::internal_allocator<typename thread_queue<Mutex, PendingQueuing, StagedQueuing, TerminatedQueuing>::task_description> task_description_alloc_

Private Types

template<>
using mutex_type = Mutex
template<>
using thread_map_type = std::unordered_set<thread_id_type, std::hash<thread_id_type>, std::equal_to<thread_id_type>, util::internal_allocator<thread_id_type>>
template<>
using thread_heap_type = std::vector<thread_id_type, util::internal_allocator<thread_id_type>>
template<>
using thread_description_ptr = typename thread_id_ref_type::thread_repr*
template<>
using work_items_type = typename PendingQueuing::template apply<thread_description_ptr>::type
template<>
using task_items_type = typename StagedQueuing::template apply<task_description*>::type
template<>
using terminated_items_type = typename TerminatedQueuing::template apply<thread_data*>::type

Private Members

thread_queue_init_parameters parameters_
mutex_type mtx_
thread_map_type thread_map_
std::atomic<std::int64_t> thread_map_count_
work_items_type work_items_
terminated_items_type terminated_items_
std::atomic<std::int64_t> terminated_items_count_
task_items_type new_tasks_
thread_heap_type thread_heap_small_
thread_heap_type thread_heap_medium_
thread_heap_type thread_heap_large_
thread_heap_type thread_heap_huge_
thread_heap_type thread_heap_nostack_
util::cache_line_data<std::atomic<std::int64_t>> new_tasks_count_
util::cache_line_data<std::atomic<std::int64_t>> work_items_count_
struct task_description

Public Members

template<>
thread_init_data data