hpx/threading/thread.hpp#

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

template<>
struct std::hash<::hpx::thread::id>#

Public Functions

inline std::size_t operator()(::hpx::thread::id const &id) const#
namespace hpx

Typedefs

using thread_termination_handler_type = hpx::function<void(std::exception_ptr const &e)>#

Functions

void set_thread_termination_handler(thread_termination_handler_type f)#
inline void swap(thread &x, thread &y) noexcept#
inline bool operator==(thread::id const &x, thread::id const &y) noexcept#
inline bool operator!=(thread::id const &x, thread::id const &y) noexcept#
inline bool operator<(thread::id const &x, thread::id const &y) noexcept#
inline bool operator>(thread::id const &x, thread::id const &y) noexcept#
inline bool operator<=(thread::id const &x, thread::id const &y) noexcept#
inline bool operator>=(thread::id const &x, thread::id const &y) noexcept#
template<typename Char, typename Traits>
std::basic_ostream<Char, Traits> &operator<<(std::basic_ostream<Char, Traits> &out, thread::id const &id)#
class thread#
#include <thread.hpp>

The class thread represents a single thread of execution. Threads allow multiple functions to execute concurrently. hreads begin execution immediately upon construction of the associated thread object (pending any OS scheduling delays), starting at the top-level function provided as a constructor argument. The return value of the top-level function is ignored and if it terminates by throwing an exception, hpx::terminate is called. The top-level function may communicate its return value or an exception to the caller via hpx::promise or by modifying shared variables (which may require synchronization, see hpx::mutex and hpx::atomic) hpx::thread objects may also be in the state that does not represent any thread (after default construction, move from, detach, or join), and a thread of execution may not be associated with any thread objects (after detach). No two hpx::thread objects may represent the same thread of execution; hpx::thread is not CopyConstructible or CopyAssignable, although it is MoveConstructible and MoveAssignable.

Public Types

typedef threads::thread_id_type native_handle_type#

Public Functions

thread() noexcept#
template<typename F, typename Enable = typename std::enable_if<!std::is_same<typename std::decay<F>::type, thread>::value>::type>
inline explicit thread(F &&f)#
template<typename F, typename ...Ts>
inline explicit thread(F &&f, Ts&&... vs)#
template<typename F>
inline thread(threads::thread_pool_base *pool, F &&f)#
template<typename F, typename ...Ts>
inline thread(threads::thread_pool_base *pool, F &&f, Ts&&... vs)#
~thread()#
thread(thread&&) noexcept#
thread &operator=(thread&&) noexcept#
void swap(thread&) noexcept#

swaps two thread objects

inline bool joinable() const noexcept#

checks whether the thread is joinable, i.e. potentially running in parallel context

void join()#

waits for the thread to finish its execution

inline void detach()#

permits the thread to execute independently from the thread handle

id get_id() const noexcept#

returns the id of the thread

inline native_handle_type native_handle() const#

returns the underlying implementation-defined thread handle

void interrupt(bool flag = true)#
bool interruption_requested() const#
hpx::future<void> get_future(error_code &ec = throws)#
std::size_t get_thread_data() const#
std::size_t set_thread_data(std::size_t)#

Public Static Functions

static unsigned int hardware_concurrency() noexcept#

returns the number of concurrent threads supported by the implementation

static void interrupt(id, bool flag = true)#

Private Types

typedef hpx::spinlock mutex_type#

Private Functions

void terminate(const char *function, const char *reason) const#
inline bool joinable_locked() const noexcept#
inline void detach_locked()#
void start_thread(threads::thread_pool_base *pool, hpx::move_only_function<void()> &&func)#

Private Members

mutable mutex_type mtx_#
threads::thread_id_ref_type id_#

Private Static Functions

static threads::thread_result_type thread_function_nullary(hpx::move_only_function<void()> const &func)#
class id#

Public Functions

id() noexcept = default#
inline explicit id(threads::thread_id_type const &i) noexcept#
inline explicit id(threads::thread_id_type &&i) noexcept#
inline explicit id(threads::thread_id_ref_type const &i) noexcept#
inline explicit id(threads::thread_id_ref_type &&i) noexcept#
inline threads::thread_id_type const &native_handle() const#

Private Members

threads::thread_id_type id_#

Friends

friend class thread
friend bool operator==(thread::id const &x, thread::id const &y) noexcept#
friend bool operator!=(thread::id const &x, thread::id const &y) noexcept#
friend bool operator<(thread::id const &x, thread::id const &y) noexcept#
friend bool operator>(thread::id const &x, thread::id const &y) noexcept#
friend bool operator<=(thread::id const &x, thread::id const &y) noexcept#
friend bool operator>=(thread::id const &x, thread::id const &y) noexcept#
template<typename Char, typename Traits>
friend std::basic_ostream<Char, Traits> &operator<<(std::basic_ostream<Char, Traits>&, thread::id const&)#
namespace this_thread

Functions

thread::id get_id() noexcept#

Returns the id of the current thread.

void yield() noexcept#

Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run.

Note

The exact behavior of this function depends on the implementation, in particular on the mechanics of the OS scheduler in use and the state of the system. For example, a first-in-first-out realtime scheduler (SCHED_FIFO in Linux) would suspend the current thread and put it on the back of the queue of the same-priority threads that are ready to run (and if there are no other threads at the same priority, yield has no effect).

void yield_to(thread::id) noexcept#
threads::thread_priority get_priority()#
std::ptrdiff_t get_stack_size()#
void interruption_point()#
bool interruption_enabled()#
bool interruption_requested()#
void interrupt()#
void sleep_until(hpx::chrono::steady_time_point const &abs_time)#

Blocks the execution of the current thread until specified abs_time has been reached.

It is recommended to use the clock tied to abs_time, in which case adjustments of the clock may be taken into account. Thus, the duration of the block might be more or less than abs_time-Clock::now() at the time of the call, depending on the direction of the adjustment and whether it is honored by the implementation. The function also may block until after abs_time has been reached due to process scheduling or resource contention delays.

Parameters

abs_time – absolute time to block until

inline void sleep_for(hpx::chrono::steady_duration const &rel_time)#

Blocks the execution of the current thread for at least the specified rel_time. This function may block for longer than rel_time due to scheduling or resource contention delays.

It is recommended to use a steady clock to measure the duration. If an implementation uses a system clock instead, the wait time may also be sensitive to clock adjustments.

Parameters

rel_time – time duration to sleep

std::size_t get_thread_data()#
std::size_t set_thread_data(std::size_t)#
class disable_interruption#

Public Functions

disable_interruption()#
~disable_interruption()#

Private Functions

disable_interruption(disable_interruption const&)#
disable_interruption &operator=(disable_interruption const&)#

Private Members

bool interruption_was_enabled_#

Friends

friend class restore_interruption
class restore_interruption#

Public Functions

explicit restore_interruption(disable_interruption &d)#
~restore_interruption()#

Private Functions

restore_interruption(restore_interruption const&)#
restore_interruption &operator=(restore_interruption const&)#

Private Members

bool interruption_was_enabled_#
namespace std
template<> id >

Public Functions

inline std::size_t operator()(::hpx::thread::id const &id) const#