-
Notifications
You must be signed in to change notification settings - Fork 1
/
main4.1.cpp
76 lines (48 loc) · 1.46 KB
/
main4.1.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
74
75
76
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include "./taskruntime4.1.h"
silk::demo_runtime_4_1::task<int> c2(const int i) {
co_await silk::demo_runtime_4_1::yield();
co_return i;
}
silk::demo_runtime_4_1::task<int> c3(const int i) {
auto r = co_await c2(i);
co_return r + 1;
}
silk::demo_runtime_4_1::task<int> c33(const int i) {
return c3(i);
}
silk::demo_runtime_4_1::task<> c31() {
silk::demo_runtime_4_1::task<int> c0 = c3(2);
auto r = co_await c0;
printf("%d c31() -> %d\n", silk::current_worker_id, r);
}
std::atomic<int> count;
silk::demo_runtime_4_1::independed_task c0() {
co_await silk::demo_runtime_4_1::yield();
silk::demo_runtime_4_1::task<int> c0 = c3( 2 );
auto r0 = co_await c3( 1 );
auto r1 = co_await c0;
auto r2 = co_await c0;
co_await c31();
auto r3 = co_await c3( 3 );
auto r4 = co_await c33( 4 );
auto r5 = co_await c33( 5 );
auto completes_synchronously = []() -> silk::demo_runtime_4_1::task<int> {
co_return 1;
};
int r6 = co_await completes_synchronously();
printf("%d c0() -> %d %d %d %d %d %d %d\n", silk::current_worker_id, r0, r1, r2, r3, r4, r5, r6);
count.fetch_add(1, std::memory_order_acquire);
}
int main() {
silk::init_pool(silk::demo_runtime_4_1::schedule, silk::makecontext);
for (int i = 0; i < 1000000; i++) {
silk::demo_runtime_4_1::spawn( c0() );
}
silk::join_main_thread_2_pool(silk::demo_runtime_4_1::schedule);
sleep(3);
printf("coros: %d\n", count.load());
return 0;
}