diff options
Diffstat (limited to 'tests/count1.c')
-rw-r--r-- | tests/count1.c | 42 |
1 files changed, 21 insertions, 21 deletions
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 <windows.h> -#include <pthread.h> +#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; } |