4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-03-02 13:05:42 +08:00

* winsup.api/pthread/condvar9.c: Fix test.

This commit is contained in:
Thomas Pfaff 2003-04-08 18:29:37 +00:00
parent 29d0fe3f74
commit e3501c78ca
2 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,7 @@
2003-04-08 Thomas Pfaff <tpfaff@gmx.net>
* winsup.api/pthread/condvar9.c: Fix test.
2003-03-27 Thomas Pfaff <tpfaff@gmx.net> 2003-03-27 Thomas Pfaff <tpfaff@gmx.net>
* winsup.api/pthread/rwlock1.c: Remove pthreads-win32 header. * winsup.api/pthread/rwlock1.c: Remove pthreads-win32 header.

View File

@ -18,7 +18,7 @@
* - * -
* *
* Description: * Description:
* - Make NUMTHREADS threads wait on CV, cancel one, broadcast signal them, * - Make NUMTHREADS threads wait on CV, broadcast signal them, cancel them
* and then repeat. * and then repeat.
* *
* Environment: * Environment:
@ -79,6 +79,7 @@ static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER;
static struct timespec abstime = { 0, 0 }; static struct timespec abstime = { 0, 0 };
static int awoken; static int awoken;
static int not_canceled;
static void * static void *
mythread(void * arg) mythread(void * arg)
@ -107,14 +108,18 @@ mythread(void * arg)
while (! (cvthing.shared > 0)) while (! (cvthing.shared > 0))
assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
assert(cvthing.shared > 0);
awoken++;
pthread_testcancel();
pthread_cleanup_pop(0); pthread_cleanup_pop(0);
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma inline_depth() #pragma inline_depth()
#endif #endif
assert(cvthing.shared > 0); not_canceled++;
awoken++;
assert(pthread_mutex_unlock(&cvthing.lock) == 0); assert(pthread_mutex_unlock(&cvthing.lock) == 0);
@ -127,7 +132,6 @@ main()
int failed = 0; int failed = 0;
int i; int i;
int first, last; int first, last;
int canceledThreads = 0;
pthread_t t[NUMTHREADS + 1]; pthread_t t[NUMTHREADS + 1];
struct timeb currSysTime; struct timeb currSysTime;
const DWORD NANOSEC_PER_MILLISEC = 1000000; const DWORD NANOSEC_PER_MILLISEC = 1000000;
@ -149,6 +153,7 @@ main()
assert((t[0] = pthread_self()) != NULL); assert((t[0] = pthread_self()) != NULL);
awoken = 0; awoken = 0;
not_canceled = 0;
for (first = 1, last = NUMTHREADS / 2; for (first = 1, last = NUMTHREADS / 2;
first < NUMTHREADS; first < NUMTHREADS;
@ -180,12 +185,11 @@ main()
cvthing.shared++; cvthing.shared++;
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
assert(pthread_cancel(t[(first + last) / 2]) == 0);
canceledThreads++;
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
for (i = first; i <= last; i++)
assert(pthread_cancel(t[i]) == 0);
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
/* /*
* Give threads time to complete. * Give threads time to complete.
@ -225,7 +229,8 @@ main()
* Check any results here. * Check any results here.
*/ */
assert(awoken == NUMTHREADS - canceledThreads); assert(awoken == NUMTHREADS);
assert(not_canceled == 0);
/* /*
* Success. * Success.