// This must execute EXACTLY n forks. void forktree(uint64 n) { if (n==0) return; // First we split without losing any: uint64 half1 = n / 2; uint64 half2 = half1 + (n % 2); cilk_spawn forktree(half2 - 1); forktree(half1); }
int main(void) { cprintf("forktree process will sleep %d ticks\n",SLEEP_TIME); sleep(SLEEP_TIME); forktree(""); return 0; }
int main(int argc, char **argv) { forktree(""); printf("forktree over!\n"); return 0; }
int main(int argc, char** argv) { uint64 n; if (argc>1) n = atoi(argv[1]); else { printf("forkbench: expects one argument!\n"); return 1; } forktree(n); return 0; }
void forkchild(const char *cur, char branch) { char nxt[DEPTH+1]; int i; if (strlen(cur) >= DEPTH) return; snprintf(nxt, DEPTH+1, "%s%c", cur, branch); if ((i = fork()) == 0) { forktree(nxt); exit(); } }
void forkchild(const char *cur, char branch) { cprintf("calling forkchild() with branch char = %c, branch = %c, envid = %d\n", cur, branch, sys_getenvid()); char nxt[DEPTH+1]; if (strlen(cur) >= DEPTH) return; snprintf(nxt, DEPTH+1, "%s%c", cur, branch); if (fork() == 0) { forktree(nxt); exit(); } }
void forkchild(const char *cur, char branch) { char nxt[DEPTH+1]; if (strlen(cur) >= DEPTH) return; snprintf(nxt, DEPTH+1, "%s%c", cur, branch); if (fork() == 0) { cprintf("%04x: I am '%c'\n", sys_getenvid(), branch); forktree(nxt); exit(); } }
void forkchild(const char *cur, char branch) { //cprintf("%c\n",branch); char nxt[DEPTH + 1]; if (strlen(cur) >= DEPTH) return; snprintf(nxt, DEPTH + 1, "%s%c", cur, branch); envid_t r; if ((r = fork()) == 0) { forktree(nxt); exit(); } else wait(r); }
void umain(void) { forktree(""); }
void umain(int argc, char **argv) { forktree(""); }
int main(void) { forktree(""); return 0; }