hpx::thread, hpx::this_thread::yield, hpx::this_thread::get_id, hpx::this_thread::sleep_for, hpx::this_thread::sleep_until
hpx::thread, hpx::this_thread::yield, hpx::this_thread::get_id, hpx::this_thread::sleep_for, hpx::this_thread::sleep_until#
Defined in header hpx/thread.hpp.
See Public API for a list of names and headers that are part of the public HPX API.
-
namespace hpx
-
Functions
-
void set_thread_termination_handler(thread_termination_handler_type f)#
-
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 Functions
-
thread() noexcept#
-
template<typename F, typename Enable = std::enable_if_t<!std::is_same_v<std::decay_t<F>, thread>>>
inline explicit thread(F &&f)#
-
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()#
-
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
-
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)#
Public Static Functions
-
static unsigned int hardware_concurrency() noexcept#
returns the number of concurrent threads supported by the implementation
Private Functions
-
void terminate(char const *function, char const *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 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_ref_type const &i) noexcept#
-
inline explicit id(threads::thread_id_ref_type &&i) noexcept#
Friends
- friend class thread
-
id() noexcept = default#
-
thread() noexcept#
-
namespace this_thread
Functions
-
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).
-
threads::thread_priority get_priority() noexcept#
-
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
-
class 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
-
disable_interruption(disable_interruption const&)#
-
class restore_interruption#
-
Private Functions
-
restore_interruption(restore_interruption const&)#
-
restore_interruption &operator=(restore_interruption const&)#
Private Members
-
bool interruption_was_enabled_#
-
restore_interruption(restore_interruption const&)#
-
void yield() noexcept#
-
void set_thread_termination_handler(thread_termination_handler_type f)#
-
namespace std
- template<> id >