-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
45 lines (37 loc) · 827 Bytes
/
Copy pathexample.c
File metadata and controls
45 lines (37 loc) · 827 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
41
42
43
#include <stdio.h>
#include <stdbool.h>
void coroutine_register(void (*func)(void));
void yield(void);
void func1(void) {
for (int i = 0; i < 8; i++) {
printf("[%d] hello from fn 1\n", i);
yield();
}
printf("fn 1 finished\n");
}
void func3(void) {
for (int i = 0; i < 8; i++) {
printf("[%d] hello from fn 3\n", i);
yield();
}
printf("fn 3 finished\n");
}
void func2(void) {
for (int i = 0; i < 5; i++) {
printf("[%d] hello from fn 2\n", i);
yield();
}
printf("fn 2 finished\n");
}
int main(void)
{
printf("start\n");
coroutine_register(func1);
coroutine_register(func2);
coroutine_register(func3);
for (int i = 1 ; i < 19; i++){
printf("hello from main\n");
yield();
}
printf("end\n");
}