Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 43 lines (35 sloc) 0.738 kB
871c6e3 @cloudwu Hello world
authored
1 #include "coroutine.h"
2 #include <stdio.h>
3
4 struct args {
5 int n;
6 };
7
8 static void
9 foo(struct schedule * S, void *ud) {
10 struct args * arg = ud;
11 int start = arg->n;
12 int i;
13 for (i=0;i<5;i++) {
14 printf("coroutine %d : %d\n",coroutine_running(S) , start + i);
15 coroutine_yield(S);
16 }
17 }
18
19 static void
20 test(struct schedule *S) {
21 struct args arg1 = { 0 };
22 struct args arg2 = { 100 };
23
24 int co1 = coroutine_new(S, foo, &arg1);
25 int co2 = coroutine_new(S, foo, &arg2);
26 printf("main start\n");
27 while (coroutine_status(S,co1) && coroutine_status(S,co2)) {
28 coroutine_resume(S,co1);
29 coroutine_resume(S,co2);
30 }
31 printf("main end\n");
32 }
33
34 int
35 main() {
36 struct schedule * S = coroutine_open();
37 test(S);
38 coroutine_close(S);
39
40 return 0;
41 }
42
Something went wrong with that request. Please try again.