54 66
68
Variable stack Coroutines WIP
on 3:07 PM Dec 23 2025
67
68
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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 *yield_files(void *param){
bool domore = true;
char *path = param;
DIR *d;
struct dirent *dir;
int pathlen = strlen(path);
d = opendir(path);
if (d) {
while (domore && (dir = readdir(d)) != NULL) {
int blklen = pathlen + 1 + strlen(dir->d_name) + 1;
char *r = malloc(blklen);
snprintf(r, blklen, "%s/%s", path, dir->d_name);
domore = Generator_Yield(r);
if (domore && dir->d_type == DT_DIR) {
if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) {
r = malloc(blklen);
snprintf(r, blklen, "%s/%s", path, dir->d_name);
domore = yield_files(r);
free(r);
}
}
}
closedir(d);
}
return (void *)domore;
}
void *gentest(void *param){
Generator gen;
Generator_ctor(&gen, yield_files, (char *)param);
int count = 0;
while(Generator_Next(&gen, &param)){
printf("%d) %s\n", count, (char *)param);
free(param);
if (++count>16000) break;
}
Generator_dtor(&gen);
return param;
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
Coroutine_Run(gentest, "..", NULL);
return 0;
}
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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>
#define DEMO_STACK_SIZE (8192*sizeof(void *))
void *yield_files(void *param){
bool domore = true;
char *path = param;
DIR *d;
struct dirent *dir;
int pathlen = strlen(path);
d = opendir(path);
if (d) {
while (domore && (dir = readdir(d)) != NULL) {
int blklen = pathlen + 1 + strlen(dir->d_name) + 1;
char *r = malloc(blklen);
snprintf(r, blklen, "%s/%s", path, dir->d_name);
domore = Generator_Yield(r);
if (domore && dir->d_type == DT_DIR) {
if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) {
r = malloc(blklen);
snprintf(r, blklen, "%s/%s", path, dir->d_name);
domore = yield_files(r);
free(r);
}
}
}
closedir(d);
}
return (void *)domore;
}
void *gentest(void *param){
Generator gen;
Generator_ctor(&gen, DEMO_STACK_SIZE, yield_files, (char *)param);
int count = 0;
while(Generator_Next(&gen, &param)){
printf("%d) %s\n", count, (char *)param);
free(param);
if (++count>16000) break;
}
Generator_dtor(&gen);
return param;
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
Coroutine_Run(DEMO_STACK_SIZE, gentest, "..", NULL);
return 0;
}