-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
73 lines (61 loc) · 1.66 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <thread>
#include <memory>
#include <atomic>
std::atomic<bool> gSyncUsersThreadRun;
void push(std::function<void()> callback)
{
callback();
}
void sync(std::function<void()> callback)
{
callback();
}
std::unique_ptr<std::thread> get_thread()
{
return std::unique_ptr<std::thread>(new std::thread([]()
{
while (gSyncUsersThreadRun.load())
{
//missing ')' but successfully compiles
std::this_thread::sleep_for(std::chrono::seconds(1);
try
{
std::cout << "Try update sync user in background mode" << std::endl;
if (false)
{
int i = 10;
sync([]()
{
push([]()
{
int j = 10;
});
});
}
std::cout << "Sync user finished" << std::endl;
}
catch (const char * e)
{
std::cout << "Sync user finished" << std::endl;
}
catch (const std::exception& ex)
{
std::cout << "Exception: " << ex.what() << "Sync with auth server was failed" << std::endl;
}
catch (...)
{
std::cout << "Got exception while processing request. Sync with auth server was failed" << std::endl;
}
}
}));
}
int main()
{
gSyncUsersThreadRun.store(true);
auto thread = get_thread();
std::this_thread::sleep_for(std::chrono::seconds(5));
gSyncUsersThreadRun.store(false);
thread->join();
return 0;
}