-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
40 lines (34 loc) · 819 Bytes
/
Copy pathmain.c
File metadata and controls
40 lines (34 loc) · 819 Bytes
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
#include "coroutine.h"
#include <stdio.h>
struct args {
int n;
};
static void //测试使用的协程执行函数
foo(struct schedule * S, void *ud) {
struct args * args = ud;
int start = args->n;
int i;
for(i=0; i<5; i++){
printf("coroutine %d : %d\n", coroutine_running(S), start + i);
coroutine_yield(S);
}
}
static void //关于两个打印协程的测试用例
test(struct schedule * S) {
struct args args1 = { 0 };
struct args args2 = { 100 };
int co1 = coroutine_new(S, foo, &args1);
int co2 = coroutine_new(S, foo, &args2);
printf("main start\n");
while(coroutine_status(S,co1) && coroutine_status(S,co2)) {
coroutine_resume(S,co1);
coroutine_resume(S,co2);
}
printf("main end\n");
}
int main() {
struct schedule * S = coroutine_open();
test(S);
coroutine_close(S);
return 0;
}