summaryrefslogtreecommitdiff
path: root/tests/condvar9.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-11-03 01:08:41 +0000
committerrpj <rpj>2004-11-03 01:08:41 +0000
commitec8290acdaea21b16d98f1ef5d4ae8a28ab2109a (patch)
tree0bd3750ec1cc12594b6cfe69473e393da6ec101b /tests/condvar9.c
parentcccaf0c2c82e78a72d69a4a50c872f308bed2f65 (diff)
Mutex, semaphore, thread ID, test suite changes - see ChangeLogs
Diffstat (limited to 'tests/condvar9.c')
-rw-r--r--tests/condvar9.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/tests/condvar9.c b/tests/condvar9.c
index b24d71e..7eb9035 100644
--- a/tests/condvar9.c
+++ b/tests/condvar9.c
@@ -86,6 +86,7 @@ typedef struct bag_t_ bag_t;
struct bag_t_ {
int threadnum;
int started;
+ int finished;
/* Add more per-thread state variables here */
};
@@ -127,8 +128,8 @@ mythread(void * arg)
assert(pthread_mutex_lock(&cvthing.lock) == 0);
/*
- * pthread_cond_timedwait is a cancelation point and we
- * going to cancel one deliberately.
+ * pthread_cond_timedwait is a cancelation point and we're
+ * going to cancel some threads deliberately.
*/
#ifdef _MSC_VER
#pragma inline_depth(0)
@@ -146,6 +147,7 @@ mythread(void * arg)
assert(cvthing.shared > 0);
awoken++;
+ bag->finished = 1;
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
@@ -164,7 +166,7 @@ main()
struct _timeb currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000;
- assert((t[0] = pthread_self()) != NULL);
+ assert((t[0] = pthread_self()).p != NULL);
assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER);
@@ -177,7 +179,7 @@ main()
abstime.tv_sec += 5;
- assert((t[0] = pthread_self()) != NULL);
+ assert((t[0] = pthread_self()).p != NULL);
awoken = 0;
@@ -185,14 +187,15 @@ main()
first < NUMTHREADS;
first = last + 1, last = NUMTHREADS)
{
+ int ct;
+
assert(pthread_mutex_lock(&start_flag) == 0);
for (i = first; i <= last; i++)
{
- threadbag[i].started = 0;
+ threadbag[i].started = threadbag[i].finished = 0;
threadbag[i].threadnum = i;
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
- assert(pthread_detach(t[i]) == 0);
}
/*
@@ -207,46 +210,47 @@ main()
*/
Sleep(1000);
+ ct = (first + last) / 2;
+ assert(pthread_cancel(t[ct]) == 0);
+ canceledThreads++;
+ assert(pthread_join(t[ct], NULL) == 0);
+
assert(pthread_mutex_lock(&cvthing.lock) == 0);
cvthing.shared++;
- assert(pthread_cancel(t[(first + last) / 2]) == 0);
- canceledThreads++;
-
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
/*
- * Give threads time to complete.
+ * Standard check that all threads started - and wait for them to finish.
*/
- Sleep(1000);
- }
-
-
- /*
- * Standard check that all threads started.
- */
- for (i = 1; i <= NUMTHREADS; i++)
- {
- failed = !threadbag[i].started;
-
- if (failed)
- {
- fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ for (i = first; i <= last; i++)
+ {
+ failed = !threadbag[i].started;
+
+ if (failed)
+ {
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ else
+ {
+ assert(pthread_join(t[i], NULL) == 0 || threadbag[i].finished == 0);
+// fprintf(stderr, "Thread %d: finished %d\n", i, threadbag[i].finished);
+ }
}
}
/*
* Cleanup the CV.
*/
-
+
assert(pthread_mutex_destroy(&cvthing.lock) == 0);
assert(cvthing.lock == NULL);
- assert(pthread_cond_destroy(&cvthing.notbusy) == 0);
+ assert_e(pthread_cond_destroy(&cvthing.notbusy), ==, 0);
assert(cvthing.notbusy == NULL);