MCPcopy Create free account
hub / github.com/David-Haim/concurrencpp / main

Function main

example/10_regular_timer/source/main.cpp:7–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace std::chrono_literals;
6
7int main() {
8 concurrencpp::runtime runtime;
9 std::atomic_size_t counter = 1;
10 concurrencpp::timer timer = runtime.timer_queue()->make_timer(1500ms, 2000ms, runtime.thread_pool_executor(), [&] {
11 const auto c = counter.fetch_add(1);
12 std::cout << "timer was invoked for the " << c << "th time" << std::endl;
13 });
14
15 std::cout << "timer due time (ms): " << timer.get_due_time().count() << std::endl;
16 std::cout << "timer frequency (ms): " << timer.get_frequency().count() << std::endl;
17 std::cout << "timer-associated executor : " << timer.get_executor()->name << std::endl;
18
19 std::this_thread::sleep_for(20s);
20
21 std::cout << "main thread cancelling timer" << std::endl;
22 timer.cancel();
23
24 std::this_thread::sleep_for(10s);
25
26 return 0;
27}

Callers

nothing calls this directly

Calls 6

get_due_timeMethod · 0.80
get_frequencyMethod · 0.80
get_executorMethod · 0.80
cancelMethod · 0.80
timer_queueMethod · 0.45
thread_pool_executorMethod · 0.45

Tested by

no test coverage detected