forked from chengxumiaodaren/BuriedPoint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_example.cc
37 lines (29 loc) · 1.2 KB
/
context_example.cc
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
#include <chrono>
#include <iostream>
#include <thread>
#include "src/context/context.h"
int main() {
buried::Context::GetGlobalContext().Start();
buried::Context::GetGlobalContext().GetMainStrand().post([]() {
std::cout << "Operation 1 executed in strand1 on thread id "
<< std::this_thread::get_id() << std::endl;
});
buried::Context::GetGlobalContext().GetReportStrand().post([]() {
std::cout << "Operation 2 executed in strand2 on thread id "
<< std::this_thread::get_id() << std::endl;
buried::Context::GetGlobalContext().GetReportStrand().post([]() {
std::cout << "Operation 3 executed in strand2 on thread id "
<< std::this_thread::get_id() << std::endl;
});
buried::Context::GetGlobalContext().GetMainStrand().post([]() {
std::cout << "Operation 4 executed in strand1 on thread id "
<< std::this_thread::get_id() << std::endl;
});
buried::Context::GetGlobalContext().GetReportStrand().post([]() {
std::cout << "Operation 5 executed in strand3 on thread id "
<< std::this_thread::get_id() << std::endl;
});
});
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;
}