52 lines1.2 KB
Newer
Older
-
+
commited
{line.log.rev}
on
9 months ago
37
1
#include <stdio.h>
2
#include <stddef.h>
3
#include "coroutine.h"
4
#include "generator.h"
5
#include "asleep.h"
6
#include "task.h"
7
8
#include <dirent.h>
9
#include <string.h>
10
#include <stdlib.h>
11
#include <time.h>
12
6 months ago
13
#define DEMO_STACK_SIZE (8192*sizeof(void *))
9 months ago
37
14
15
void *chaindeeper(void *param){
16
// enough headroom for printf on an Intel Mac - your system may be different
17
if (Coroutine_GetStackHeadroom() < 2000){
6 months ago
18
void *result;
Last week
19
bool fail = Coroutine_Chain(DEMO_STACK_SIZE, 0, chaindeeper, param, &result);
6 months ago
20
return fail ? NULL : result;
9 months ago
37
21
}
8 months ago
22
printf("%ld %ld\n", (long)param, Coroutine_GetStackHeadroom());
9 months ago
37
23
long depth = (long)param;
24
if (depth > 10000){
25
return NULL;
26
}
27
return chaindeeper((void *)(depth + 1));
28
}
29
30
31
void *chaintest(
32
void *param
33
){
34
(void)param;
35
36
chaindeeper((void *)0);
4 months ago
37
Coroutine_Report report = Coroutine_GetReport();
38
printf("%d routines using a pool of %d, min headroom %zu\n", report.coroutines_created, report.coroutines_pool_size, report.lowest_headroom);
9 months ago
37
39
40
return param;
41
}
42
43
44
int main(int argc, char *argv[]) {
45
(void)argc;
46
(void)argv;
47
Last week
48
Coroutine_Run(DEMO_STACK_SIZE, 0, chaintest, NULL, NULL);
9 months ago
37
49
4 months ago
50
return 0;
9 months ago
37
51
}
52