11 #include "../core_export.h" 12 #include "../object.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>
106 static thread& current_thread();
110 intptr handle() const noexcept;
114 bool is_alive() const noexcept;
126 bool is_background() const noexcept;
137 thread& is_background(
bool value);
141 bool is_main_thread() const noexcept;
146 bool is_thread_pool_thread() const noexcept;
152 bool joinable() const noexcept;
157 static
thread& main_thread();
163 int32 managed_thread_id() const noexcept;
198 intptr thread_id() const noexcept;
232 bool join(
int32 milliseconds_timeout);
246 static
void join_all();
253 static
bool join_all(
int32 milliseconds_timeout);
260 static
bool join_all(const
time_span& timeout);
265 template<typename collection_t>
272 template<
typename collection_t>
273 static bool join_all(
const collection_t& threads,
int32 milliseconds_timeout) {
274 std::vector<thread*> thread_pointers;
275 for (
auto& item : threads)
276 thread_pointers.push_back(const_cast<thread*>(&item));
277 return join_all_ptr(thread_pointers, milliseconds_timeout);
284 template<
typename collection_t>
296 static void sleep(
int32 milliseconds_timeout);
308 static void spin_wait(
int32 iterations);
345 template<
typename item_t>
346 static bool join_all(
const std::initializer_list<item_t>& threads) {
return join_all(threads,
timeout::infinite);}
347 template<
typename item_t>
348 static bool join_all(
const std::initializer_list<item_t>& threads,
int32 milliseconds_timeout) {
349 std::vector<thread*> thread_pointers;
350 for (
auto& item : threads)
351 thread_pointers.push_back(const_cast<thread*>(&item));
352 return join_all_ptr(thread_pointers, milliseconds_timeout);
354 template<
typename item_t>
356 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads);
357 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads,
int32 milliseconds_timeout);
358 static bool join_all(
const std::initializer_list<std::shared_ptr<thread>>& threads,
const time_span& timeout);
359 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads);
360 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads,
int32 milliseconds_timeout);
361 static bool join_all(
const std::initializer_list<std::unique_ptr<thread>>& threads,
const time_span& timeout);
362 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads);
363 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads,
int32 milliseconds_timeout);
364 static bool join_all(
const std::vector<std::shared_ptr<thread>>& threads,
const time_span& timeout);
365 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads);
366 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads,
int32 milliseconds_timeout);
367 static bool join_all(
const std::vector<std::unique_ptr<thread>>& threads,
const time_span& timeout);
368 template <
typename start_t>
370 template <
typename start_t>
380 static int32 generate_managed_thread_id() noexcept;
381 static intptr get_current_thread_handle();
382 static intptr get_current_thread_id();
383 static static_data& get_static_data();
385 void interrupt_internal();
386 bool is_aborted()
const noexcept;
387 bool is_stopped()
const noexcept;
388 bool is_suspended()
const noexcept;
389 void is_thread_pool_thread(
bool value) noexcept;
390 bool is_unmanaged_thread()
const noexcept;
391 bool is_unstarted()
const noexcept;
392 bool is_wait_sleep_join()
const noexcept;
393 static bool join_all_ptr(
const std::vector<thread*>& threads,
int32 milliseconds_timeout);
395 static thread& unmanaged_thread();
397 static constexpr
int32 main_managed_thread_id = 1;
398 static constexpr
int32 unmanaged_thread_id = 0;
400 std::shared_ptr<data> data_;
401 static intptr main_thread_id_;
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition: thread.h:54
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
Contains xtd::threading::wait_handle exception.
int32 as< int32 >(std::any value)
Casts a type into another type.
Definition: as.h:9228
Contains xtd::threading::parameterized_thread_start exception.
thread_state
Specifies the execution states of a System::Threading::Thread.
Definition: thread_state.h:22
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:273
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::threading::thread_start exception.
std::chrono::milliseconds total_milliseconds_duration() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds...
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Definition: thread_pool.h:50
thread_priority
Specifies the scheduling priority of a system::threading::thread.
Definition: thread_priority.h:22
static void join_all(const collection_t &threads)
Blocks the calling thread until all specified joinable threads collection terminate.
Definition: thread.h:266
static constexpr int32 infinite
A constant used to specify an infinite waiting period. This field is constant.
Definition: timeout.h:39
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:285
delegate< void(std::any)> parameterized_thread_start
Represents the method that executes on a xtd::threading::thread.
Definition: parameterized_thread_start.h:24
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Creates and controls a thread, sets its priority, and gets its status.
Definition: thread.h:41
static const intptr invalid_thread_id
Represents an invalid native operating system thread id. This field is read-only. ...
Definition: thread.h:58
Contains xtd::threading::thread_state enumeration.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents a time interval.
Definition: time_span.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains a constant used to specify an infinite amount of time. This class cannot be inherited...
Definition: timeout.h:31
Contains xtd::threading::thread_priority enumeration.
delegate< void()> thread_start
Represents the method that executes on a xtd::threading::thread.
Definition: thread_start.h:22
Encapsulates operating system specific objects that wait for exclusive access to shared resources...
Definition: wait_handle.h:48