Skip to content

Instantly share code, notes, and snippets.

@boompig
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boompig/9754781 to your computer and use it in GitHub Desktop.
Save boompig/9754781 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int counter = 0;
#define MAX_WORKERS 10
void worker() {
// do stuff;
counter--;
}
int main() {
int i;
int pid;
for (i = 0; i < MAX_WORKERS; i++) {
pid = fork();
if (pid != 0) {
counter++;
worker();
}
}
while(counter != 0) {
// busy wait
}
printf("Workers are done %s\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment