93 template<
class start_t>
95 template<
class start_t>
97 thread(thread&&) =
default;
98 thread(
const thread&) =
default;
99 thread& operator=(
const thread&);
320 template<class collection_t>
327 template<
class collection_t>
328 static bool join_all(
const collection_t& threads,
int32 milliseconds_timeout) {
330 for (
auto& item : threads)
331 thread_pointers.
resize(thread_pointers.size() + 1,
const_cast<thread*
>(&item));
332 return join_all_ptr(thread_pointers, milliseconds_timeout);
328 static bool join_all(
const collection_t& threads,
int32 milliseconds_timeout) {
…}
339 template<
class collection_t>
368 template<class item_t>
370 template<
class item_t>
371 static bool join_all(
const std::initializer_list<item_t>& threads,
int32 milliseconds_timeout) {
373 for (
auto& item : threads)
374 thread_pointers.
resize(thread_pointers.size() + 1,
const_cast<thread*
>(&item));
375 return join_all_ptr(thread_pointers, milliseconds_timeout);
377 template<
class item_t>
378 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()));}
380 static bool join_all(
const std::initializer_list<
xtd::sptr<thread>>& threads, int32 milliseconds_timeout);
381 static bool join_all(
const std::initializer_list<
xtd::sptr<thread>>& threads,
const time_span& timeout);
383 static bool join_all(
const std::initializer_list<
xtd::uptr<thread>>& threads, int32 milliseconds_timeout);
384 static bool join_all(
const std::initializer_list<
xtd::uptr<thread>>& threads,
const time_span& timeout);
386 static bool join_all(
const xtd::array<
xtd::sptr<thread>>& threads, int32 milliseconds_timeout);
387 static bool join_all(
const xtd::array<
xtd::sptr<thread>>& threads,
const time_span& timeout);
389 static bool join_all(
const xtd::array<
xtd::uptr<thread>>& threads, int32 milliseconds_timeout);
390 static bool join_all(
const xtd::array<
xtd::uptr<thread>>& threads,
const time_span& timeout);
391 template<
class start_t>
392 static thread start_new(start_t start) {
return start_new(thread_start {
start});}
393 template<
class start_t>
394 static thread start_new(start_t start,
const xtd::any_object& obj) {
return start_new(parameterized_thread_start {
start}, obj);}
398 friend class thread_pool;
399 friend class wait_handle;
402 static bool do_wait(wait_handle& wait_handle, int32 milliseconds_timeout);
403 static int32 generate_managed_thread_id() noexcept;
404 static intptr get_current_thread_handle();
405 static intptr get_current_thread_id() noexcept;
406 static static_data& get_static_data();
407 static thread& get_thread(intptr thread_id);
408 void interrupt_internal();
409 bool is_aborted() const noexcept;
410 bool is_stopped() const noexcept;
411 bool is_suspended() const noexcept;
412 void is_thread_pool_thread(
bool value) noexcept;
413 bool is_unmanaged_thread() const noexcept;
414 bool is_unstarted() const noexcept;
415 bool is_wait_sleep_join() const noexcept;
416 static
bool join_all_ptr(const xtd::array<thread*>& threads, int32 milliseconds_timeout);
418 static thread& unmanaged_thread();
420 static constexpr int32 main_managed_thread_id = 1;
421 static constexpr int32 unmanaged_thread_id = 0;
423 xtd::sptr<data> data_;
424 static intptr main_thread_id_;
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
void resize(size_type new_size, value_type value)
Resizes the container to contain count elements, does nothing if count == size(). / @param new_size T...
Definition basic_array.hpp:405
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:85
object()=default
Create a new instance of the ultimate base class object.
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Definition thread_pool.hpp:52
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:45
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.
xtd::threading::thread_priority priority() const noexcept
Gets a value indicating the scheduling priority of a thread.
bool is_background() const noexcept
Gets a value indicating whether or not a thread is a background thread.
intptr thread_id() const noexcept
Gets the native operating system thread id.
static void join_all(const collection_t &threads)
Blocks the calling thread until all specified joinable threads collection terminate.
Definition thread.hpp:321
void interrupt()
Interrupts a thread that is in the xtd::threading::thread_state::wait_sleep_join thread state.
void suspend()
Either suspends the thread, or if the thread is already suspended, has no effect (Should not be used)...
static thread & current_thread() noexcept
Gets the currently running thread.
intptr handle() const noexcept
Gets the native operating system handle.
static thread start_new(const xtd::threading::thread_start &start)
Create and immedialtely start a xtd::threading::thread with specified method.
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
string name() const noexcept
Gets the name of the thread.
bool auto_join() const noexcept
Gets a value indicating the current thread wiil be joined when destroyed.
void detach()
Sets the thread background.
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
void start()
Causes the operating system to change the state of the current instance to xtd::threading::thread_sta...
int32 managed_thread_id() const noexcept
Gets a unique identifier for the current managed thread.
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition thread.hpp:56
void join()
Blocks the calling thread until this thread object terminates, while continuing to perform standard C...
static void join_all()
Blocks the calling thread until all joinable threads terminate.
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.hpp:340
static void spin_wait(int32 iterations)
Causes a thread to wait the number of times defined by the iterations parameter.
static bool yield() noexcept
Causes the calling thread to yield execution to another thread that is ready to run on the current pr...
bool is_alive() const noexcept
Gets a value indicating the execution status of the current thread.
bool is_main_thread() const noexcept
Gets a value indicating the current thread is the main thread.
static thread & main_thread()
Gets the main thread.
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.hpp:328
void resume()
Resumes a thread that has been suspended (Should not be used).
static const intptr invalid_thread_id
Represents an invalid native operating system thread id. This field is read-only.
Definition thread.hpp: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...
bool joinable() const noexcept
Gets a value indicating the current thread is joinable.
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 ...
bool is_thread_pool_thread() const noexcept
Gets a value indicating whether or not a thread belongs to the managed thread pool.
xtd::threading::thread_state thread_state() const noexcept
Gets a value containing the states of the current thread.
void abort()
Raises a xtd::threading::thread_aborted_exception in the thread on which it is invoked,...
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
static constexpr int32 infinite
A constant used to specify an infinite waiting period. This field is constant.
Definition timeout.hpp:41
Represents a time interval.
Definition time_span.hpp:29
Contains core_export_ keyword.
Contains xtd::date_time class.
xtd::delegate< void(const xtd::any_object &obj)> parameterized_thread_start
Represents the method that executes on a xtd::threading::thread.
Definition parameterized_thread_start.hpp:29
xtd::delegate< void()> thread_start
Represents the method that executes on a xtd::threading::thread.
Definition thread_start.hpp:24
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::intptr get_id() noexcept
Returns the thread id of the current thread.
xtd::intptr handle() noexcept
Gets the thread handle of the current thread.
xtd::threading::thread_priority priority() noexcept
Gets the thread priority of the current thread.
xtd::intptr thread_id() noexcept
Gets the thread id of the current thread.
void sleep_until(const xtd::date_time &sleep_time)
Stops the execution of the current thread until a specified time point.
xtd::int32 managed_thread_id() noexcept
Gets the managed thread id of the current thread.
xtd::string name() noexcept
Gets the thread name of the current thread.
void sleep_for(const xtd::time_span &sleep_duration)
Stops the execution of the current thread for a specified time duration.
bool yield() noexcept
Suggests that the implementation reschedule execution of threads.
thread_priority
Specifies the scheduling priority of a system::threading::thread.
Definition thread_priority.hpp:24
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ start
Starting of a logical operation.
Definition trace_event_type.hpp:37
Contains xtd::intptr type.
The xtd::threading::this_thread namespace contains some current thread properties and sheduling metho...
Definition thread.hpp:428
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::object class.
Contains xtd::threading::parameterized_thread_start delegate.
Contains xtd::threading::thread_priority enumeration.
Contains xtd::threading::thread_start delegate.
Contains xtd::threading::thread_state enumeration.
Contains xtd::time_span class.
Contains xtd fundamental types.
Contains xtd::threading::wait_handle class.