summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrpj <rpj>2002-02-20 05:07:06 +0000
committerrpj <rpj>2002-02-20 05:07:06 +0000
commit0b88f4cb25866bcbb80f15374aa3981db932f62f (patch)
treef186f8b7f190a7a3b383871b8a68efc0ac6858f6 /tests
parent6f75a28b2891ce728bc9fddd2400abd9570c3867 (diff)
spin4.c: Try to force the main thread to wait.
Diffstat (limited to 'tests')
-rw-r--r--tests/spin4.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/tests/spin4.c b/tests/spin4.c
index 1287a7f..3cd6d64 100644
--- a/tests/spin4.c
+++ b/tests/spin4.c
@@ -54,10 +54,10 @@ static int washere = 0;
void * func(void * arg)
{
_ftime(&currSysTimeStart);
+ washere = 1;
assert(pthread_spin_lock(&lock) == 0);
assert(pthread_spin_unlock(&lock) == 0);
_ftime(&currSysTimeStop);
- washere = 1;
return (void *) GetDurationMilliSecs(currSysTimeStart, currSysTimeStop);
}
@@ -69,6 +69,7 @@ main()
int i;
pthread_t t;
int CPUs;
+ struct _timeb sysTime;
if ((CPUs = pthread_num_processors_np()) == 1)
{
@@ -80,15 +81,17 @@ main()
assert(pthread_create(&t, NULL, func, NULL) == 0);
- /*
- * 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++)
+ while (washere == 0)
+ {
+ sched_yield();
+ }
+
+ do
{
sched_yield();
+ _ftime(&sysTime);
}
+ while (GetDurationMilliSecs(currSysTimeStart, sysTime) <= 1000);
assert(pthread_spin_unlock(&lock) == 0);