From 2ef097640758653a0e9d63e90a4aac329cd86368 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 22 Feb 1999 02:54:12 +0000 Subject: 1999-02-23 Ross Johnson * Makefile: Some refinement. * *.c: More exhaustive checking through assertions; clean up; add some more tests. --- tests/count1.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'tests/count1.c') diff --git a/tests/count1.c b/tests/count1.c index c4e0c4e..61e82e0 100644 --- a/tests/count1.c +++ b/tests/count1.c @@ -7,8 +7,7 @@ * Test some basic assertions about the number of threads at runtime. */ -#include -#include +#include "test.h" static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t threads[10]; @@ -27,36 +26,37 @@ myfunc(void *arg) int main() { - int i, result; + int i; int maxThreads = sizeof(threads) / sizeof(pthread_t); - /* Spawn ten threads. Each thread should increment the numThreads - variable, sleep for one second, decrement the variable and then - exit. The final result of numThreads should be 1 again. */ + /* + * Spawn ten threads. Each thread should increment the numThreads + * variable, sleep for one second, decrement the variable and then + * exit. The final result of numThreads should be 1 again. + */ for (i = 0; i < maxThreads; i++) { - result = pthread_create(&threads[i], NULL, myfunc, 0); - if (result != 0) - { - return 1; - } + assert(pthread_create(&threads[i], NULL, myfunc, 0) == 0); } - /* Wait for all the threads to exit. */ + /* + * Wait for all the threads to exit. + */ for (i = 0; i < maxThreads; i++) { - pthread_join(threads[i], NULL); - pthread_mutex_lock(&lock); + assert(pthread_join(threads[i], NULL) == 0); + assert(pthread_mutex_lock(&lock) == 0); numThreads--; - pthread_mutex_unlock(&lock); + assert(pthread_mutex_unlock(&lock) == 0); } - /* Check the number of live threads. */ - if (numThreads != 1) - { - return 1; - } + /* + * Check the number of live threads. + */ + assert(numThreads == 1); - /* Success. */ + /* + * Success. + */ return 0; } -- cgit v1.2.3