#include #include /* NULL */ #include #include /* nanosleep(3) */ #include /* u_char */ #include /* struct timeval */ #include /* event_init(3) event_loop(3) */ #include static unsigned int counter; static void count_null_catch(void *str,enum thread_errno err, void *null) { return /* void */; } /* count_null_catch() */ static void *count_null_run(void *str, void *null, unsigned timeout) { return NULL; } /* count_null_run() */ static void count_catch(void *str,enum thread_errno err, void *null) { printf("%s\n", (char *)str); counter--; (void)thread_run(&count_null_run, NULL, THREAD_PRI_NORM, &count_null_catch, NULL, 0); } /* count_catch() */ static void *count_run(void *str, void *null, unsigned timeout) { struct timespec ts = { 1, 0 }; (void)nanosleep(&ts, 0); return str; } /* count_run() */ int main(void) { const char *list[] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", NULL }; const char **str; int i; event_init(); assert(0 == thread_init(0, 0)); for (i = 0; i < 3; i++) { counter = (sizeof list / sizeof *list) - 1; for (str = list; *str; str++) (void)thread_run(&count_run, (void *)*str, THREAD_PRI_NORM, &count_catch, NULL, 0); while (0 == event_loop(EVLOOP_ONCE)) { if (!(counter > 0)) break; } assert(0 == thread_reset(0, 0)); } return (counter == 0)? EXIT_SUCCESS : EXIT_FAILURE; } /* main() */