-
Notifications
You must be signed in to change notification settings - Fork 47
/
twoCoroTest.c
44 lines (34 loc) · 883 Bytes
/
twoCoroTest.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
#include "Coro.h"
#include <stdio.h>
Coro *firstCoro, *secondCoro;
void secondTask(void *context)
{
int num = 0;
printf("secondTask created with value %d\n", *(int *)context);
while (1)
{
printf("secondTask: %d %d\n", (int)Coro_bytesLeftOnStack(secondCoro), num++);
Coro_switchTo_(secondCoro, firstCoro);
}
}
void firstTask(void *context)
{
int value = 2;
int num = 0;
printf("firstTask created with value %d\n", *(int *)context);
secondCoro = Coro_new();
Coro_startCoro_(firstCoro, secondCoro, (void *)&value, secondTask);
while (1)
{
printf("firstTask: %d %d\n", (int)Coro_bytesLeftOnStack(firstCoro), num++);
Coro_switchTo_(firstCoro, secondCoro);
}
}
int main()
{
Coro *mainCoro = Coro_new();
int value = 1;
Coro_initializeMainCoro(mainCoro);
firstCoro = Coro_new();
Coro_startCoro_(mainCoro, firstCoro, (void *)&value, firstTask);
}