-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
58 lines (51 loc) · 1.18 KB
/
test.c
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
// coop (c) Nikolas Wipper 2021
#include <stdio.h>
#include <stdlib.h>
#include "lib/coop.h"
void my_nested_async_func() {
int i = 21;
puts("Nested1: 1");
yield;
printf("Nested1: Saved %d in stack\n", i);
}
void my_nested_async_func2() {
int i = 22;
puts("Nested2: 1");
yield;
printf("Nested2: Saved %d in stack\n", i);
}
void my_async_func() {
int i = 11;
puts("Func1: 1");
yield;
printf("Func1: Saved %d in stack\n", i);
yield;
my_nested_async_func();
yield;
puts("Func1: Ran nested function");
dump;
}
void my_async_func2() {
int i = 12;
puts("Func2: 1");
yield;
printf("Func2: Saved %d in stack\n", i);
yield;
my_nested_async_func2();
yield;
puts("Func2: Ran nested function");
dump;
}
int main() {
coop_context ctx = {0};
task_t t1 = {0}, t2 = {0};
coop_stack s1 = {.size = 4096, .stack_bottom = malloc(4096)};
coop_stack s2 = {.size = 4096, .stack_bottom = malloc(4096)};
add_task(&ctx, &t1, s1, my_async_func);
add_task(&ctx, &t2, s2, my_async_func2);
start(&ctx);
puts("Ran tasks");
free(s1.stack_bottom);
free(s2.stack_bottom);
return 0;
}