Skip to content

Commit

Permalink
Refine busy.c
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Jan 9, 2025
1 parent 4b8db81 commit 87cb8c9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tests/busy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 87cb8c9

Please sign in to comment.