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