Shows how to use call_once struct.
#include <xtd/xtd>
auto main() -> int {
console::write_line("(main) begin");
auto thread_proc = [&] {
static auto cpt = 0;
[[maybe_unused]]
static auto __call_once__ =
call_once {} + [&] {
console::write_line(" (thread_proc) call once {} times", cpt + 1);
};
console::write_line(" (thread_proc) running {} times", ++cpt);
if (cpt == 3) mre.set();
};
thread_pool::register_wait_for_single_object(mre, thread_proc, {}, 100, false);
mre.wait_one();
thread::join_all();
console::write_line("(main) end");
}
Represents a thread synchronization event that, when signaled, must be reset manually....
Definition manual_reset_event.hpp:35
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
The xtd::call_once struct can be used to execute a routine exactly once. This can be used to initiali...
Definition call_once.hpp:19