#include #include #include #include #include #include int main(void) { pid_t pid; unsigned i, n = 100; unsigned quagga = 0; while (n --> 0) { for (i = 0; i < 100; i++) { if (atomic_cas_uint(&quagga, 0, 1) != 0) err(1, "bad %ua", i); pid = fork(); if (quagga != 1) err(1, "bad %ub", i); if (atomic_cas_uint(&quagga, 1, 0) != 1) err(1, "bad %uc", i); switch (pid) { case -1: /* error */ err(1, "fork"); case 0: /* child */ _exit(1); default: /* parent */ break; } } while (waitpid(-1, NULL, 0) != -1) continue; if (errno != ECHILD) err(1, "waitpid"); } return 0; }