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/spin4.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/spin4.c')
-rw-r--r-- | tests/spin4.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/spin4.c b/tests/spin4.c index a435d04..5f04a27 100644 --- a/tests/spin4.c +++ b/tests/spin4.c @@ -1,19 +1,14 @@ /* * spin4.c * - * Declare a spinlock object, lock it, spin on it, + * Declare a static spinlock object, lock it, spin on it, * and then unlock it again. - * - * For this to work on a single processor machine we have - * to static initialise the spinlock. This bypasses the - * check of the number of processors done by pthread_spin_init. - * This is a non-portable side-effect of this implementation. */ #include "test.h" #include <sys/timeb.h> -pthread_spinlock_t lock = PTHREADS_SPINLOCK_INITIALIZER; +pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER; struct _timeb currSysTimeStart; struct _timeb currSysTimeStop; @@ -37,7 +32,16 @@ int main() { long result = 0; + int i; pthread_t t; + int CPUs; + + if (pthread_getprocessors_np(&CPUs) != 0 || CPUs == 1) + { + printf("This test is not applicable to this system.\n"); + printf("Either there is only 1 CPU or the no. could not be determined.\n"); + exit(0); + } assert(pthread_spin_lock(&lock) == 0); @@ -47,6 +51,7 @@ main() * This should relinqish the CPU to the func thread enough times * to waste approximately 2000 millisecs only if the lock really * is spinning in the func thread (assuming 10 millisec CPU quantum). + */ for (i = 0; i < 200; i++) { sched_yield(); |