1 | #include <thread> |
---|---|
2 | #include <cstring> |
3 | #include <unistd.h> |
4 | using namespace std; |
5 | |
6 | bool done = false; |
7 | void foo() { |
8 | int x = 0; |
9 | for (int i = 0; i < 10000; i++) |
10 | x++; |
11 | sleep(seconds: 1); |
12 | for (int i = 0; i < 10000; i++) |
13 | x++; |
14 | done = true; |
15 | } |
16 | |
17 | void bar() { |
18 | int y = 0; |
19 | while (!done) { |
20 | y++; |
21 | } |
22 | printf("bar %d\n", y); |
23 | } |
24 | |
25 | int main() { |
26 | std::thread first(foo); |
27 | std::thread second(bar); |
28 | first.join(); |
29 | second.join(); |
30 | |
31 | printf("complete\n"); |
32 | return 0; |
33 | |
34 | } |
35 |