11#include "../core_export.h"
13#include "../time_span.h"
48 using thread_collection = std::vector<xtd::sptr<thread>>;
93 template <
typename start_t>
95 template <
typename start_t>
97 thread(thread&&) =
default;
98 thread(
const thread&) =
default;
99 thread& operator=(
const thread&);
120 bool is_alive() const noexcept;
132 bool is_background() const noexcept;
148 bool is_main_thread() const noexcept;
153 bool is_thread_pool_thread() const noexcept;
159 bool joinable() const noexcept;
165 int32 managed_thread_id() const noexcept;
169 string name() const noexcept;
215 static
thread& current_thread() noexcept;
248 bool join(
int32 milliseconds_timeout);
270 void start(std::any obj);
297 static
void join_all();
304 static
bool join_all(
int32 milliseconds_timeout);
316 template<typename collection_t>
317 static
void join_all(const collection_t& threads) {
join_all(threads, timeout::infinite);}
323 template<
typename collection_t>
324 static bool join_all(
const collection_t& threads,
int32 milliseconds_timeout) {
325 std::vector<thread*> thread_pointers;
326 for (
auto& item : threads)
327 thread_pointers.push_back(
const_cast<thread*
>(&item));
328 return join_all_ptr(thread_pointers, milliseconds_timeout);
335 template<
typename collection_t>
364 template<
typename item_t>
365 static bool join_all(
const std::initializer_list<item_t>& threads) {
return join_all(threads, timeout::infinite);}
366 template<
typename item_t>
367 static bool join_all(
const std::initializer_list<item_t>& threads,
int32 milliseconds_timeout) {
368 std::vector<thread*> thread_pointers;
369 for (
auto& item : threads)
370 thread_pointers.push_back(const_cast<
thread*>(&item));
371 return join_all_ptr(thread_pointers, milliseconds_timeout);
373 template<
typename item_t>
374 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()));}
376 static bool join_all(
const std::initializer_list<
xtd::sptr<thread>>& threads, int32 milliseconds_timeout);
377 static bool join_all(
const std::initializer_list<
xtd::sptr<thread>>& threads,
const time_span& timeout);
379 static bool join_all(
const std::initializer_list<
xtd::uptr<thread>>& threads, int32 milliseconds_timeout);
380 static bool join_all(
const std::initializer_list<
xtd::uptr<thread>>& threads,
const time_span& timeout);
382 static bool join_all(
const std::vector<
xtd::sptr<thread>>& threads, int32 milliseconds_timeout);
383 static bool join_all(
const std::vector<
xtd::sptr<thread>>& threads,
const time_span& timeout);
385 static bool join_all(
const std::vector<
xtd::uptr<thread>>& threads, int32 milliseconds_timeout);
386 static bool join_all(
const std::vector<
xtd::uptr<thread>>& threads,
const time_span& timeout);
387 template <
typename start_t>
388 static thread start_new(start_t start) {
return start_new(thread_start {start});}
389 template <
typename start_t>
390 static thread start_new(start_t start, std::any obj) {
return start_new(parameterized_thread_start {
start}, obj);}
394 friend class thread_pool;
395 friend class wait_handle;
398 static bool do_wait(wait_handle& wait_handle, int32 milliseconds_timeout);
399 static int32 generate_managed_thread_id() noexcept;
400 static intptr get_current_thread_handle();
401 static intptr get_current_thread_id() noexcept;
402 static static_data& get_static_data();
403 static thread& get_thread(intptr thread_id);
404 void interrupt_internal();
405 bool is_aborted() const noexcept;
406 bool is_stopped() const noexcept;
407 bool is_suspended() const noexcept;
408 void is_thread_pool_thread(
bool value) noexcept;
409 bool is_unmanaged_thread() const noexcept;
410 bool is_unstarted() const noexcept;
411 bool is_wait_sleep_join() const noexcept;
412 static
bool join_all_ptr(const std::vector<thread*>& threads, int32 milliseconds_timeout);
414 static thread& unmanaged_thread();
416 static constexpr int32 main_managed_thread_id = 1;
417 static constexpr int32 unmanaged_thread_id = 0;
419 xtd::sptr<data> data_;
420 static intptr main_thread_id_;
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.h:43
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:317
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
bool auto_join() const noexcept
Gets a value indicating the current thread wiil be joined when destroyed.
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition thread.h:56
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:336
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:324
static const intptr invalid_thread_id
Represents an invalid native operating system thread id. This field is read-only.
Definition thread.h:60
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:33
#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:24
thread_priority
Specifies the scheduling priority of a system::threading::thread.
Definition thread_priority.h:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.h:25
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.h:25
delegate< void(std::any)> parameterized_thread_start
Represents the method that executes on a xtd::threading::thread.
Definition parameterized_thread_start.h:26
delegate< void()> thread_start
Represents the method that executes on a xtd::threading::thread.
Definition thread_start.h:24
@ 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:29
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.