Shows how to use xtd::threading::jthread class.
#include <xtd/threading/jthread>
#include <xtd/block_scope>
#include <xtd/console>
auto main() -> int {
auto thread_proc = [] {
thread::current_thread().name("thread_proc");
for (auto index = 0; index < 10; ++index, thread::sleep(100_ms))
console::write_line(" ({}) index = {}", thread::current_thread().name(), index);
};
thread::current_thread().name("main");
console::write_line("({}) begin", thread::current_thread().name());
block_scope_(
auto thread1 = jthread::start_new(thread_proc)) {
}
console::write_line("({}) end", thread::current_thread().name());
}
#define block_scope_(...)
The specified expression is cleared automatically when the scope is ended.
Definition block_scope.hpp:25
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10