51 lines1.1 KB
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
13
14void *chaindeeper(void *param){
15 // enough headroom for printf on an Intel Mac - your system may be different
16 if (Coroutine_GetStackHeadroom() < 2000){
17 void *result;
18 bool fail = Coroutine_Chain(chaindeeper, param, &result);
19 return fail ? NULL : result;
20 }
21 printf("%ld %ld\n", (long)param, Coroutine_GetStackHeadroom());
22 long depth = (long)param;
23 if (depth > 10000){
24 return NULL;
25 }
26 return chaindeeper((void *)(depth + 1));
27}
28
29
30void *chaintest(
31 void *param
32){
33 (void)param;
34
35 chaindeeper((void *)0);
36
37 return param;
38}
39
40
41int main(int argc, char *argv[]) {
42 (void)argc;
43 (void)argv;
44
45 Coroutine_StartSystem();
46 Coroutine_Run(chaintest, NULL, NULL);
47 Coroutine_Report report = Coroutine_StopSystem();
48
49 printf("%d routines using a pool of %d, min headroom %d\n", report.coroutines_created, report.coroutines_pool_size, report.lowest_headroom);
50}
51