diff options
author | rpj <rpj> | 2001-07-06 18:16:50 +0000 |
---|---|---|
committer | rpj <rpj> | 2001-07-06 18:16:50 +0000 |
commit | 06974b302eaf8f08382e6e786aea53f420c12222 (patch) | |
tree | 1b574a41dacc634a105a74127b2dac30a60bda13 /tests/barrier4.c | |
parent | 7a3104dc65b469cbb9c88b6a9c7b7bea4126a43e (diff) |
Spinlocks and barriers fixed and working. Beta level.
* spin.c: Revamped and working; included static initialiser.
* barrier.c: Likewise.
* condvar.c: Macro constant change; inline auto init routine.
* mutex.c: Likewise.
* rwlock.c: Likewise.
* private.c: Add support for spinlock initialiser.
* global.c: Likewise.
* implement.h: Likewise.
* pthread.h (PTHREAD_SPINLOCK_INITIALIZER): Fix typo.
tests/ChangeLog:
* spin3.c: Changed test and fixed.
* spin4.c: Fixed.
* barrier3.c: Fixed.
* barrier4.c: Fixed.
Diffstat (limited to 'tests/barrier4.c')
-rw-r--r-- | tests/barrier4.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/tests/barrier4.c b/tests/barrier4.c index 1dd8291..8f33e85 100644 --- a/tests/barrier4.c +++ b/tests/barrier4.c @@ -14,12 +14,11 @@ enum { pthread_barrier_t barrier = NULL; pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER; -static int result1 = -1; -static int result2 = -1; static int serialThreadCount = 0; static int otherThreadCount = 0; -void * func(void * arg) +void * +func(void * arg) { int result = pthread_barrier_wait(&barrier); @@ -32,31 +31,39 @@ void * func(void * arg) { otherThreadCount++; } - assert(pthread_mutex_lock(&mx) == 0); + assert(pthread_mutex_unlock(&mx) == 0); return NULL; } - + int main() { + int i, j; pthread_t t[NUMTHREADS + 1]; - assert(pthread_barrier_init(&barrier, NULL, NUMTHREADS) == 0); - - for (i = 0; i < NUMTHREADS; i++) + for (j = 1; j <= NUMTHREADS; j++) { - assert(pthread_create(&t[i], NULL, func, NULL) == 0); - } + printf("Barrier height = %d\n", j); - for (i = 0; i < NUMTHREADS; i++) - { - assert(pthread_join(t[i], NULL) == 0); - } + serialThreadCount = 0; + + assert(pthread_barrier_init(&barrier, NULL, j) == 0); + + for (i = 1; i <= j; i++) + { + assert(pthread_create(&t[i], NULL, func, NULL) == 0); + } - assert(serialThreadCount == 1); + for (i = 1; i <= j; i++) + { + assert(pthread_join(t[i], NULL) == 0); + } - assert(pthread_barrier_destroy(&barrier) == 0); + assert(serialThreadCount == 1); + + assert(pthread_barrier_destroy(&barrier) == 0); + } assert(pthread_mutex_destroy(&mx) == 0); |