11#include "../core_export.h"
13#include "../time_span.h"
46 using thread_collection = std::vector<std::shared_ptr<thread>>;
91 template <
typename start_t>
93 template <
typename start_t>
95 thread(thread&&) =
default;
96 thread(
const thread&) =
default;
97 thread& operator=(
const thread&);
111 bool is_alive() const noexcept;
123 bool is_background() const noexcept;
138 bool is_main_thread() const noexcept;
143 bool is_thread_pool_thread() const noexcept;
149 bool joinable() const noexcept;
155 int32 managed_thread_id() const noexcept;
204 static
thread& current_thread() noexcept;
237 bool join(
int32 milliseconds_timeout);
259 void start(std::any obj);
286 static
void join_all();
293 static
bool join_all(
int32 milliseconds_timeout);
305 template<typename collection_t>
306 static
void join_all(const collection_t& threads) {
join_all(threads, timeout::infinite);}
312 template<
typename collection_t>
313 static bool join_all(
const collection_t& threads,
int32 milliseconds_timeout) {
314 std::vector<thread*> thread_pointers;
315 for (
auto& item : threads)
316 thread_pointers.push_back(
const_cast<thread*
>(&item));
317 return join_all_ptr(thread_pointers, milliseconds_timeout);
324 template<
typename collection_t>
353 template<
typename item_t>
354 static bool join_all(
const std::initializer_list<item_t>& threads) {
return join_all(threads, timeout::infinite);}
355 template<
typename item_t>
356 static bool join_all(
const std::initializer_list<item_t>& threads,
int32 milliseconds_timeout) {
357 std::vector<thread*> thread_pointers;
358 for (
auto& item : threads)
359 thread_pointers.push_back(const_cast<
thread*>(&item));
360 return join_all_ptr(thread_pointers, milliseconds_timeout);
362 template<
typename item_t>
363 static bool join_all(
const std::initializer_list<item_t>& threads,
const time_span& timeout) {
return join_all(threads, as<int32>(timeout.
total_milliseconds_duration().count()));}
364 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads);
365 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads, int32 milliseconds_timeout);
366 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads,
const time_span& timeout);
367 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads);
368 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads, int32 milliseconds_timeout);
369 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads,
const time_span& timeout);
370 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads);
371 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads, int32 milliseconds_timeout);
372 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads,
const time_span& timeout);
373 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads);
374 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads, int32 milliseconds_timeout);
375 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads,
const time_span& timeout);
376 template <
typename start_t>
377 static thread start_new(start_t start) {
return start_new(thread_start {start});}
378 template <
typename start_t>
379 static thread start_new(start_t start, std::any obj) {
return start_new(parameterized_thread_start {
start}, obj);}
383 friend class thread_pool;
384 friend class wait_handle;
387 static bool do_wait(wait_handle& wait_handle, int32 milliseconds_timeout);
388 static int32 generate_managed_thread_id() noexcept;
389 static intptr get_current_thread_handle();
390 static intptr get_current_thread_id() noexcept;
391 static static_data& get_static_data();
392 static thread& get_thread(intptr thread_id);
393 void interrupt_internal();
394 bool is_aborted() const noexcept;
395 bool is_stopped() const noexcept;
396 bool is_suspended() const noexcept;
397 void is_thread_pool_thread(
bool value) noexcept;
398 bool is_unmanaged_thread() const noexcept;
399 bool is_unstarted() const noexcept;
400 bool is_wait_sleep_join() const noexcept;
401 static
bool join_all_ptr(const std::vector<thread*>& threads, int32 milliseconds_timeout);
403 static thread& unmanaged_thread();
405 static constexpr int32 main_managed_thread_id = 1;
406 static constexpr int32 unmanaged_thread_id = 0;
408 std::shared_ptr<data> data_;
409 static intptr main_thread_id_;
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.h:41
thread(const xtd::threading::parameterized_thread_start &start)
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an ...
thread(const xtd::threading::thread_start &start)
Initializes a new instance of the xtd::threading::thread class.
static void join_all(const collection_t &threads)
Blocks the calling thread until all specified joinable threads collection terminate.
Definition thread.h:306
intptr handle() const noexcept
Gets the native operating system handle.
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition thread.h:54
static bool join_all(const collection_t &threads, const time_span &timeout)
Blocks the calling thread until all specified joinable threads collection terminate or the specified ...
Definition thread.h:325
static void spin_wait(int32 iterations)
Causes a thread to wait the number of times defined by the iterations parameter.
static bool yield()
Causes the calling thread to yield execution to another thread that is ready to run on the current pr...
static bool join_all(const collection_t &threads, int32 milliseconds_timeout)
Blocks the calling thread until all specified joinable threads collection terminate or the specified ...
Definition thread.h:313
static const intptr invalid_thread_id
Represents an invalid native operating system thread id. This field is read-only.
Definition thread.h:58
static void sleep(const time_span &timeout)
Suspends the current thread for a specified time.
thread(const xtd::threading::thread_start &start, int32 max_stack_size)
Initializes a new instance of the xtd::threading::thread class, specifying the maximum stack size for...
thread(const xtd::threading::parameterized_thread_start &start, int32 max_stack_size)
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an ...
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.h:31
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
#define core_export_
Define shared library export.
Definition core_export.h:13
thread_state
Specifies the execution states of a System::Threading::Thread.
Definition thread_state.h:22
thread_priority
Specifies the scheduling priority of a system::threading::thread.
Definition thread_priority.h:22
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
intmax_t intptr
Represent a pointer or a handle.
Definition types.h:153
delegate< void(std::any)> parameterized_thread_start
Represents the method that executes on a xtd::threading::thread.
Definition parameterized_thread_start.h:24
delegate< void()> thread_start
Represents the method that executes on a xtd::threading::thread.
Definition thread_start.h:22
@ start
Starting of a logical operation.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::threading::parameterized_thread_start exception.
Represents a time interval.
Definition time_span.h:26
std::chrono::milliseconds total_milliseconds_duration() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds...
Contains xtd::threading::thread_priority enumeration.
Contains xtd::threading::thread_start exception.
Contains xtd::threading::thread_state enumeration.
Contains xtd::threading::wait_handle exception.