#include #include #include #include #include #include #include #include #include #include struct params { int argc; char **argv; char **envp; pthread_t parent; pthread_t sibling[30]; }; static void *dump_thread(void *arg) { struct params *params = arg; void *retval; int i; pthread_join(params->parent, &retval); fprintf(stdout, "Waiting for 5s\n"); sleep(5); fprintf(stdout, "Dumping\n"); abort(); fprintf(stdout, "Abort Failed: %d %s\n", errno, strerror(errno)); for (i = 0; i <= 29; i++) { pthread_join(params->sibling[i], &retval); } fprintf(stdout, "All Done!\n"); _exit(EXIT_FAILURE); return NULL; } static void *idle_thread(void *arg) { unsigned long i = (unsigned long)arg; sleep(10); fprintf(stdout, "Done %lu\n", i); fflush(stdout); return NULL; } int main(int argc, char **argv, char **envp) { struct params *params; pthread_t pt; unsigned long i; params = malloc(sizeof(struct params)); params->argc = argc - 1; params->argv = argv = argv + 1; params->envp = envp; params->parent = pthread_self(); pthread_create(&pt, NULL, dump_thread, params); for (i = 0; i <= 29; i++) pthread_create(¶ms->sibling[i], NULL, idle_thread, (void *)i); pthread_exit(NULL); return 0; }