-
Notifications
You must be signed in to change notification settings - Fork 1
/
lwan-coro-example.c
50 lines (40 loc) · 1.03 KB
/
lwan-coro-example.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
#include <stdio.h>
#include "lwan-coro.h"
int coro_func_foo(coro_t *coro, void *data) {
printf("called coro_func_foo\n");
printf("yield in coro_func_foo\n");
coro_yield(coro, 0);
printf("continue in coro_func_foo\n");
return 0;
}
int coro_func_bar(coro_t *coro, void *data) {
printf("called coro_func_bar\n");
printf("yield in coro_func_bar\n");
coro_yield(coro, 0);
printf("continue in coro_func_bar\n");
return 0;
}
int main() {
coro_switcher_t switcher;
printf("coro_new coro1 and coro2\n");
coro_t *coro1 = coro_new(&switcher, &coro_func_foo, NULL);
coro_t *coro2 = coro_new(&switcher, &coro_func_bar, NULL);
coro_resume(coro1);
coro_resume(coro2);
coro_resume(coro1);
coro_resume(coro2);
printf("coro_free coro1 and coro2\n");
coro_free(coro1);
coro_free(coro2);
return 0;
}
/*
* coro_new coro1 and coro2
* called coro_func_foo
* yield in coro_func_foo
* called coro_func_bar
* yield in coro_func_bar
* continue in coro_func_foo
* continue in coro_func_bar
* coro_free coro1 and coro2
* */