51 52
56
66 67
Remove stack_per_coroutine
on 12:32 PM Nov 18 2025
55
56
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
45
46
47
48
49
#include <stdio.h>
#include <stddef.h>
#include "coroutine.h"
#include "generator.h"
#include "asleep.h"
#include "task.h"
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void *chaindeeper(void *param){
// enough headroom for printf on an Intel Mac - your system may be different
if (Coroutine_GetStackHeadroom() < 2000){
return Coroutine_Chain(chaindeeper, param);
}
printf("%ld %ld\n", (long)param, Coroutine_GetStackHeadroom());
long depth = (long)param;
if (depth > 10000){
return NULL;
}
return chaindeeper((void *)(depth + 1));
}
void *chaintest(
void *param
){
(void)param;
chaindeeper((void *)0);
return param;
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
Coroutine_StartSystem();
Coroutine_Run(chaintest, NULL);
Coroutine_Report report = Coroutine_StopSystem();
printf("%d routines using a pool of %d, min headroom %d, stack used for each coroutine %lu\n", report.coroutines_created, report.coroutines_pool_size, report.lowest_headroom, report.stack_per_coroutine);
}
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
45
46
47
48
49
#include <stdio.h>
#include <stddef.h>
#include "coroutine.h"
#include "generator.h"
#include "asleep.h"
#include "task.h"
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void *chaindeeper(void *param){
// enough headroom for printf on an Intel Mac - your system may be different
if (Coroutine_GetStackHeadroom() < 2000){
return Coroutine_Chain(chaindeeper, param);
}
printf("%ld %ld\n", (long)param, Coroutine_GetStackHeadroom());
long depth = (long)param;
if (depth > 10000){
return NULL;
}
return chaindeeper((void *)(depth + 1));
}
void *chaintest(
void *param
){
(void)param;
chaindeeper((void *)0);
return param;
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
Coroutine_StartSystem();
Coroutine_Run(chaintest, NULL);
Coroutine_Report report = Coroutine_StopSystem();
printf("%d routines using a pool of %d, min headroom %d\n", report.coroutines_created, report.coroutines_pool_size, report.lowest_headroom);
}