diff options
author | rpj <rpj> | 1999-02-22 02:54:12 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-02-22 02:54:12 +0000 |
commit | 2ef097640758653a0e9d63e90a4aac329cd86368 (patch) | |
tree | 71751f699b0aedba3227446ac228d30f2a127173 /tests/count1.c | |
parent | 943bc9bb02212649a83ec32152299d50d34226e6 (diff) |
1999-02-23 Ross Johnson <rpj@ise.canberra.edu.au>
* Makefile: Some refinement.
* *.c: More exhaustive checking through assertions; clean up;
add some more tests.
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; } |