xtd 0.2.0
Loading...
Searching...
No Matches
xtd::call_once Struct Reference

Definition

The xtd::call_once struct can be used to execute a routine exactly once. This can be used to initialise data in a thread-safe way.

Namespace
xtd
Library
xtd.core
Remarks
See also call_once_ keyword helper.
Examples
The following example shows how to use xtd::call_once struct.
#include <xtd/xtd>
auto main() -> int {
console::write_line("(main) begin");
auto mre = manual_reset_event {};
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");
}
// This code produces the following output :
//
// (main) begin
// (thread_proc) call once 1 times
// (thread_proc) running 1 times
// (thread_proc) running 2 times
// (thread_proc) running 3 times
// (main) end
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
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

The documentation for this struct was generated from the following file: