-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (25 loc) · 672 Bytes
/
main.cpp
File metadata and controls
35 lines (25 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include "SimpleTimer.hpp"
using namespace std;
void task1(const string &out)
{
cout << out.c_str() << endl;
}
int main() {
// store the result of a call to std::bind
//Timer t1(bind(task1, "hello"), 1000);
//Timer t2(bind(task1, "bye"), 2000);
// or
// store a lambda
std::function<void()> f_task_hello = []() { task1("hello"); };
std::function<void()> f_task_bye = []() { task1("bye"); };
Timer t1(f_task_hello, 1000);
Timer t2(f_task_bye, 2000);
t1.start();
t2.start();
// Do other stuff
std::this_thread::sleep_for(chrono::seconds(10));
t1.stop();
t2.stop();
return 0;
}