diff --git a/testing/getprime/getprime_main.c b/testing/getprime/getprime_main.c index 198f4a5ca..910aef797 100644 --- a/testing/getprime/getprime_main.c +++ b/testing/getprime/getprime_main.c @@ -102,8 +102,7 @@ static FAR void *thread_func(FAR void *param) printf("thread #%d finished, found %d primes, last one was %d\n", no, count, last); - pthread_exit(NULL); - return NULL; /* To keep some compilers happy */ + return NULL; } /**************************************************************************** @@ -141,6 +140,14 @@ static void get_prime_in_parallel(int n) printf("Set thread policy to SCHED_FIFO\n"); #endif + /* Zero threads, do work from main thread instead. */ + + if (n == 0) + { + arg[0] = n; + thread_func((FAR void *)&arg[0]); + } + for (i = 0; i < n; i++) { arg[i] = i; @@ -161,6 +168,19 @@ static void get_prime_in_parallel(int n) UNUSED(status); } +/**************************************************************************** + * Name: usage + ****************************************************************************/ + +static void usage(void) +{ + printf("\nUsage: getprime []\n"); + printf("\nWhere:\n"); + printf(" is integer from 0 to %d (default 1).\n", + MAX_THREADS); + exit(0); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -180,9 +200,14 @@ int main(int argc, FAR char *argv[]) if (argc == 2) { n = (int)strtol(argv[1], &endp, 10); - ASSERT(argv[1] != endp); - - ASSERT(0 < n && n <= MAX_THREADS); + if (argv[1] == endp || n < 0 || n > MAX_THREADS) + { + usage(); + } + } + else if (argc > 2) + { + usage(); } clock_gettime(CLOCK_REALTIME, &ts0);