diff --git a/tests/busy.c b/tests/busy.c index d7ca0d4b..48c6c304 100644 --- a/tests/busy.c +++ b/tests/busy.c @@ -13,29 +13,36 @@ static void *loop(void *param __attribute__((unused))) { - volatile int unused_value = 0; while (1) - (void)unused_value; + ; return NULL; } int main(int argc, char *argv[]) { - size_t i; + int i; + pthread_t *threads; int num_threads = argc == 2 ? atoi(argv[1]) : get_ncpu(); num_threads = MAX(num_threads, 1); + threads = (pthread_t *)malloc((size_t)num_threads * sizeof(pthread_t)); increase_priority(); - for (i = 0; i < (size_t)(num_threads - 1); i++) + for (i = 0; i < num_threads; i++) { - pthread_t thread; int ret; - if ((ret = pthread_create(&thread, NULL, &loop, NULL)) != 0) + if ((ret = pthread_create(&threads[i], NULL, loop, NULL)) != 0) { printf("pthread_create() failed. Error code %d\n", ret); + free(threads); exit(EXIT_FAILURE); } } - loop(NULL); + + for (i = 0; i < num_threads; i++) + { + pthread_join(threads[i], NULL); + } + + free(threads); return 0; }