-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
45 lines (33 loc) · 1.03 KB
/
main.cpp
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
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include "timer.h"
using namespace std;
void func1() {
cout << "Hello from func1" << endl;
}
void func2(const std::string_view str, const std::string_view str2) {
cout << str << str2 <<endl;
}
#include <condition_variable>
#include <mutex>
void cv_func(bool& processed, std::condition_variable& cv)
{
processed = true;
cv.notify_all();
}
int main() {
Timer t = Timer();
t.repeat(std::chrono::milliseconds(1000), func2, "This is the value", "this is my 2nd parameter");
t.once(std::chrono::seconds (1000), []() { std::cout << "This is my timer" << std::endl;});
{
bool processed = false;
std::condition_variable cv;
std::mutex m;
t.once(std::chrono::microseconds (1000), cv_func, std::ref(processed), std::ref(cv));
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [&] { return processed; });
}
std::cout << "MAIN MAIN MAIN" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds (5000));
t.stop();
}