From 33507f86e1f086dcece131f9d9b8cfa968b5c3e6 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 18 Apr 2005 04:53:55 +0000 Subject: '' --- tests/ChangeLog | 15 ++ tests/condvar3.c | 299 +++++++++++++++--------------- tests/condvar3_1.c | 402 ++++++++++++++++++++-------------------- tests/condvar3_2.c | 386 +++++++++++++++++++------------------- tests/condvar3_3.c | 264 +++++++++++++------------- tests/condvar4.c | 338 ++++++++++++++++----------------- tests/condvar5.c | 336 ++++++++++++++++----------------- tests/condvar6.c | 483 +++++++++++++++++++++++------------------------ tests/condvar7.c | 516 +++++++++++++++++++++++++-------------------------- tests/condvar8.c | 516 +++++++++++++++++++++++++-------------------------- tests/condvar9.c | 536 ++++++++++++++++++++++++++--------------------------- 11 files changed, 2050 insertions(+), 2041 deletions(-) (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index da6b15c..d02bce0 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,18 @@ +2005-04-18 Ross Johnson + + * condvar3.c: Remove locks from around signalling calls - should not + be required for normal operation and only serve to mask deficiencies; + ensure that CV destruction is not premature after removing guards. + * condvar3_1.c: Likewise. + * condvar3_2.c: Likewise. + * condvar3_3.c: Likewise. + * condvar4.c: Likewise. + * condvar5.c: Likewise. + * condvar6.c: Likewise. + * condvar7.c: Likewise. + * condvar8.c: Likewise. + * condvar9.c: Likewise. + 2005-04-11 Ross Johnson * once4.c: New test; tries to test priority adjustments diff --git a/tests/condvar3.c b/tests/condvar3.c index f650d15..60cd0e7 100644 --- a/tests/condvar3.c +++ b/tests/condvar3.c @@ -1,151 +1,148 @@ -/* - * File: condvar3.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test basic function of a CV - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - The primary thread takes the lock before creating any threads. - * The secondary thread blocks on the lock allowing the primary - * thread to enter the cv wait state which releases the lock. - * The secondary thread then takes the lock and signals the waiting - * primary thread. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns 0. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -static pthread_cond_t cv; -static pthread_mutex_t mutex; -static int shared = 0; - -enum { - NUMTHREADS = 2 /* Including the primary thread. */ -}; - -void * -mythread(void * arg) -{ - int result = 0; - - assert(pthread_mutex_lock(&mutex) == 0); - - shared++; - - if ((result = pthread_cond_signal(&cv)) != 0) - { - printf("Error = %s\n", error_string[result]); - } - assert(result == 0); - - assert(pthread_mutex_unlock(&mutex) == 0); - - return (void *) 0; -} - -int -main() -{ - pthread_attr_t attr; - pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert(pthread_attr_init(&attr) == 0); - assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); - - assert((t[0] = pthread_self()).p != NULL); - - assert(pthread_cond_init(&cv, NULL) == 0); - - assert(pthread_mutex_init(&mutex, NULL) == 0); - - assert(pthread_mutex_lock(&mutex) == 0); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - assert(pthread_create(&t[1], &attr, mythread, (void *) 1) == 0); - - abstime.tv_sec += 5; - - while (! (shared > 0)) - assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0); - - assert(shared > 0); - - assert(pthread_mutex_unlock(&mutex) == 0); - - assert(pthread_cond_destroy(&cv) == 0); - - return 0; -} +/* + * File: condvar3.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test basic function of a CV + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - The primary thread takes the lock before creating any threads. + * The secondary thread blocks on the lock allowing the primary + * thread to enter the cv wait state which releases the lock. + * The secondary thread then takes the lock and signals the waiting + * primary thread. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns 0. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +static pthread_cond_t cv; +static pthread_mutex_t mutex; +static int shared = 0; + +enum { + NUMTHREADS = 2 /* Including the primary thread. */ +}; + +void * +mythread(void * arg) +{ + int result = 0; + + assert(pthread_mutex_lock(&mutex) == 0); + shared++; + assert(pthread_mutex_unlock(&mutex) == 0); + + if ((result = pthread_cond_signal(&cv)) != 0) + { + printf("Error = %s\n", error_string[result]); + } + assert(result == 0); + + + return (void *) 0; +} + +int +main() +{ + pthread_t t[NUMTHREADS]; + struct timespec abstime = { 0, 0 }; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert((t[0] = pthread_self()).p != NULL); + + assert(pthread_cond_init(&cv, NULL) == 0); + + assert(pthread_mutex_init(&mutex, NULL) == 0); + + assert(pthread_mutex_lock(&mutex) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); + + abstime.tv_sec += 5; + + while (! (shared > 0)) + assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0); + + assert(shared > 0); + + assert(pthread_mutex_unlock(&mutex) == 0); + + assert(pthread_join(t[1], NULL) == 0); + + assert(pthread_cond_destroy(&cv) == 0); + + return 0; +} diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c index 19ce9e7..369c07c 100644 --- a/tests/condvar3_1.c +++ b/tests/condvar3_1.c @@ -1,201 +1,201 @@ -/* - * File: condvar3_1.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test timeout of multiple waits on a CV with some signaled. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Because some CVs are never signaled, we expect their waits to time out. - * Some are signaled, the rest time out. Pthread_cond_destroy() will fail - * unless all are accounted for, either signaled or timedout. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait does not return ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#define _WIN32_WINNT 0x400 - -#include "test.h" -#include - -static pthread_cond_t cv; -static pthread_cond_t cv1; -static pthread_mutex_t mutex; -static pthread_mutex_t mutex1; -static struct timespec abstime = { 0, 0 }; -static int timedout = 0; -static int signaled = 0; -static int awoken = 0; -static int waiting = 0; - -enum { - NUMTHREADS = 30 -}; - -void * -mythread(void * arg) -{ - int result; - - assert(pthread_mutex_lock(&mutex1) == 0); - ++waiting; - assert(pthread_cond_signal(&cv1) == 0); - assert(pthread_mutex_unlock(&mutex1) == 0); - - assert(pthread_mutex_lock(&mutex) == 0); - result = pthread_cond_timedwait(&cv, &mutex, &abstime); - if (result == ETIMEDOUT) - { - timedout++; - } - else - { - awoken++; - } - assert(pthread_mutex_unlock(&mutex) == 0); - - return arg; -} - -#include "../implement.h" - -int -main() -{ - int i; - pthread_t t[NUMTHREADS + 1]; - int result = 0; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert(pthread_cond_init(&cv, NULL) == 0); - assert(pthread_cond_init(&cv1, NULL) == 0); - - assert(pthread_mutex_init(&mutex, NULL) == 0); - assert(pthread_mutex_init(&mutex1, NULL) == 0); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert(pthread_mutex_lock(&mutex1) == 0); - - for (i = 1; i <= NUMTHREADS; i++) - { - assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0); - } - - do { - assert(pthread_cond_wait(&cv1,&mutex1) == 0); - } while ( NUMTHREADS > waiting ); - - assert(pthread_mutex_unlock(&mutex1) == 0); - - for (i = NUMTHREADS/3; i <= 2*NUMTHREADS/3; i++) - { - assert(pthread_mutex_lock(&mutex) == 0); - assert(pthread_cond_signal(&cv) == 0); - assert(pthread_mutex_unlock(&mutex) == 0); - - signaled++; - } - - for (i = 1; i <= NUMTHREADS; i++) - { - assert(pthread_join(t[i], (void **) &result) == 0); - assert(result == i); - } - - fprintf(stderr, "awk = %d\n", awoken); - fprintf(stderr, "sig = %d\n", signaled); - fprintf(stderr, "tot = %d\n", timedout); - - assert(signaled == awoken); - assert(timedout == NUMTHREADS - signaled); - - assert(pthread_cond_destroy(&cv1) == 0); - - { - int result = pthread_cond_destroy(&cv); - if (result != 0) - { - fprintf(stderr, "Result = %s\n", error_string[result]); - fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); - fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); - fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); - fflush(stderr); - } - assert(result == 0); - } - - assert(pthread_mutex_destroy(&mutex1) == 0); - assert(pthread_mutex_destroy(&mutex) == 0); - - return 0; -} +/* + * File: condvar3_1.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test timeout of multiple waits on a CV with some signaled. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Because some CVs are never signaled, we expect their waits to time out. + * Some are signaled, the rest time out. Pthread_cond_destroy() will fail + * unless all are accounted for, either signaled or timedout. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait does not return ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#define _WIN32_WINNT 0x400 + +#include "test.h" +#include + +static pthread_cond_t cv; +static pthread_cond_t cv1; +static pthread_mutex_t mutex; +static pthread_mutex_t mutex1; +static struct timespec abstime = { 0, 0 }; +static int timedout = 0; +static int signaled = 0; +static int awoken = 0; +static int waiting = 0; + +enum { + NUMTHREADS = 30 +}; + +void * +mythread(void * arg) +{ + int result; + + assert(pthread_mutex_lock(&mutex1) == 0); + ++waiting; + assert(pthread_mutex_unlock(&mutex1) == 0); + assert(pthread_cond_signal(&cv1) == 0); + + assert(pthread_mutex_lock(&mutex) == 0); + result = pthread_cond_timedwait(&cv, &mutex, &abstime); + if (result == ETIMEDOUT) + { + timedout++; + } + else + { + awoken++; + } + assert(pthread_mutex_unlock(&mutex) == 0); + + return arg; +} + +#include "../implement.h" + +int +main() +{ + int i; + pthread_t t[NUMTHREADS + 1]; + int result = 0; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert(pthread_cond_init(&cv, NULL) == 0); + assert(pthread_cond_init(&cv1, NULL) == 0); + + assert(pthread_mutex_init(&mutex, NULL) == 0); + assert(pthread_mutex_init(&mutex1, NULL) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert(pthread_mutex_lock(&mutex1) == 0); + + for (i = 1; i <= NUMTHREADS; i++) + { + assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0); + } + + do { + assert(pthread_cond_wait(&cv1,&mutex1) == 0); + } while ( NUMTHREADS > waiting ); + + assert(pthread_mutex_unlock(&mutex1) == 0); + + for (i = NUMTHREADS/3; i <= 2*NUMTHREADS/3; i++) + { +// assert(pthread_mutex_lock(&mutex) == 0); + assert(pthread_cond_signal(&cv) == 0); +// assert(pthread_mutex_unlock(&mutex) == 0); + + signaled++; + } + + for (i = 1; i <= NUMTHREADS; i++) + { + assert(pthread_join(t[i], (void **) &result) == 0); + assert(result == i); + } + + fprintf(stderr, "awk = %d\n", awoken); + fprintf(stderr, "sig = %d\n", signaled); + fprintf(stderr, "tot = %d\n", timedout); + + assert(signaled == awoken); + assert(timedout == NUMTHREADS - signaled); + + assert(pthread_cond_destroy(&cv1) == 0); + + { + int result = pthread_cond_destroy(&cv); + if (result != 0) + { + fprintf(stderr, "Result = %s\n", error_string[result]); + fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); + fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); + fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); + fflush(stderr); + } + assert(result == 0); + } + + assert(pthread_mutex_destroy(&mutex1) == 0); + assert(pthread_mutex_destroy(&mutex) == 0); + + return 0; +} diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c index b78e34e..c9d58ad 100644 --- a/tests/condvar3_2.c +++ b/tests/condvar3_2.c @@ -1,193 +1,193 @@ -/* - * File: condvar3_2.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test timeout of multiple waits on a CV with remainder broadcast awoken. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Because some CVs are never signaled, we expect their waits to time out. - * Some time out, the rest are broadcast signaled. Pthread_cond_destroy() will fail - * unless all are accounted for, either signaled or timedout. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait does not return ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#define _WIN32_WINNT 0x400 - -#include "test.h" -#include - -static pthread_cond_t cv; -static pthread_mutex_t mutex; -static struct timespec abstime = { 0, 0 }; -static struct timespec abstime2 = { 0, 0 }; -static int timedout = 0; -static int awoken = 0; - -enum { - NUMTHREADS = 30 -}; - -void * -mythread(void * arg) -{ - int result; - - assert(pthread_mutex_lock(&mutex) == 0); - - abstime2.tv_sec = abstime.tv_sec; - - if ((int) arg % 3 == 0) - { - abstime2.tv_sec += 2; - } - - result = pthread_cond_timedwait(&cv, &mutex, &abstime2); - if (result == ETIMEDOUT) - { - timedout++; - } - else - { - awoken++; - } - - assert(pthread_mutex_unlock(&mutex) == 0); - - return arg; -} - -#include "../implement.h" - -int -main() -{ - int i; - pthread_t t[NUMTHREADS + 1]; - int result = 0; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert(pthread_cond_init(&cv, NULL) == 0); - - assert(pthread_mutex_init(&mutex, NULL) == 0); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = abstime.tv_sec = currSysTime.time + 5; - abstime.tv_nsec = abstime2.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - assert(pthread_mutex_lock(&mutex) == 0); - - for (i = 1; i <= NUMTHREADS; i++) - { - assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0); - } - - assert(pthread_mutex_unlock(&mutex) == 0); - - for (i = 1; i <= NUMTHREADS; i++) - { - assert(pthread_join(t[i], (void **) &result) == 0); - assert(result == i); - /* - * Approximately 2/3rds of the threads are expected to time out. - * Signal the remainder after some threads have woken up and exited - * and while some are still waking up after timeout. - * Also tests that redundant broadcasts don't return errors. - */ - - assert(pthread_mutex_lock(&mutex) == 0); - - if (awoken > NUMTHREADS/3) - { - assert(pthread_cond_broadcast(&cv) == 0); - } - - assert(pthread_mutex_unlock(&mutex) == 0); - - } - - assert(awoken == NUMTHREADS - timedout); - - { - int result = pthread_cond_destroy(&cv); - if (result != 0) - { - fprintf(stderr, "Result = %s\n", error_string[result]); - fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); - fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); - fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); - fflush(stderr); - } - assert(result == 0); - } - - assert(pthread_mutex_destroy(&mutex) == 0); - - return 0; -} +/* + * File: condvar3_2.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test timeout of multiple waits on a CV with remainder broadcast awoken. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Because some CVs are never signaled, we expect their waits to time out. + * Some time out, the rest are broadcast signaled. Pthread_cond_destroy() will fail + * unless all are accounted for, either signaled or timedout. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait does not return ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#define _WIN32_WINNT 0x400 + +#include "test.h" +#include + +static pthread_cond_t cv; +static pthread_mutex_t mutex; +static struct timespec abstime = { 0, 0 }; +static struct timespec abstime2 = { 0, 0 }; +static int timedout = 0; +static int awoken = 0; + +enum { + NUMTHREADS = 30 +}; + +void * +mythread(void * arg) +{ + int result; + + assert(pthread_mutex_lock(&mutex) == 0); + + abstime2.tv_sec = abstime.tv_sec; + + if ((int) arg % 3 == 0) + { + abstime2.tv_sec += 2; + } + + result = pthread_cond_timedwait(&cv, &mutex, &abstime2); + assert(pthread_mutex_unlock(&mutex) == 0); + if (result == ETIMEDOUT) + { + InterlockedIncrement((LPLONG)&timedout); + } + else + { + InterlockedIncrement((LPLONG)&awoken); + } + + + return arg; +} + +#include "../implement.h" + +int +main() +{ + int i; + pthread_t t[NUMTHREADS + 1]; + int result = 0; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert(pthread_cond_init(&cv, NULL) == 0); + + assert(pthread_mutex_init(&mutex, NULL) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = abstime.tv_sec = currSysTime.time + 5; + abstime.tv_nsec = abstime2.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + assert(pthread_mutex_lock(&mutex) == 0); + + for (i = 1; i <= NUMTHREADS; i++) + { + assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0); + } + + assert(pthread_mutex_unlock(&mutex) == 0); + + for (i = 1; i <= NUMTHREADS; i++) + { + assert(pthread_join(t[i], (void **) &result) == 0); + assert(result == i); + /* + * Approximately 2/3rds of the threads are expected to time out. + * Signal the remainder after some threads have woken up and exited + * and while some are still waking up after timeout. + * Also tests that redundant broadcasts don't return errors. + */ + +// assert(pthread_mutex_lock(&mutex) == 0); + + if (InterlockedExchangeAdd((LPLONG)&awoken, 0L) > NUMTHREADS/3) + { + assert(pthread_cond_broadcast(&cv) == 0); + } + +// assert(pthread_mutex_unlock(&mutex) == 0); + + } + + assert(awoken == NUMTHREADS - timedout); + + { + int result = pthread_cond_destroy(&cv); + if (result != 0) + { + fprintf(stderr, "Result = %s\n", error_string[result]); + fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); + fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); + fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); + fflush(stderr); + } + assert(result == 0); + } + + assert(pthread_mutex_destroy(&mutex) == 0); + + return 0; +} diff --git a/tests/condvar3_3.c b/tests/condvar3_3.c index f6b9aa5..840a83b 100644 --- a/tests/condvar3_3.c +++ b/tests/condvar3_3.c @@ -1,132 +1,132 @@ -/* - * File: condvar3_3.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test timeouts and lost signals on a CV. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait does not return ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -/* Timur Aydin (taydin@snet.net) */ - -#include "test.h" - -#include - -pthread_cond_t cnd; -pthread_mutex_t mtx; - -int main() -{ - int rc; - - struct timespec abstime = { 0, 0 }; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert(pthread_cond_init(&cnd, 0) == 0); - assert(pthread_mutex_init(&mtx, 0) == 0); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - abstime.tv_sec += 1; - - /* Here pthread_cond_timedwait should time out after one second. */ - - assert(pthread_mutex_lock(&mtx) == 0); - - assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); - - assert(pthread_mutex_unlock(&mtx) == 0); - - /* Here, the condition variable is signaled, but there are no - threads waiting on it. The signal should be lost and - the next pthread_cond_timedwait should time out too. */ - - assert(pthread_mutex_lock(&mtx) == 0); - - assert((rc = pthread_cond_signal(&cnd)) == 0); - - assert(pthread_mutex_unlock(&mtx) == 0); - - assert(pthread_mutex_lock(&mtx) == 0); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - abstime.tv_sec += 1; - - assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); - - assert(pthread_mutex_unlock(&mtx) == 0); - - return 0; -} +/* + * File: condvar3_3.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test timeouts and lost signals on a CV. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait does not return ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +/* Timur Aydin (taydin@snet.net) */ + +#include "test.h" + +#include + +pthread_cond_t cnd; +pthread_mutex_t mtx; + +int main() +{ + int rc; + + struct timespec abstime = { 0, 0 }; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert(pthread_cond_init(&cnd, 0) == 0); + assert(pthread_mutex_init(&mtx, 0) == 0); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + abstime.tv_sec += 1; + + /* Here pthread_cond_timedwait should time out after one second. */ + + assert(pthread_mutex_lock(&mtx) == 0); + + assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); + + assert(pthread_mutex_unlock(&mtx) == 0); + + /* Here, the condition variable is signaled, but there are no + threads waiting on it. The signal should be lost and + the next pthread_cond_timedwait should time out too. */ + +// assert(pthread_mutex_lock(&mtx) == 0); + + assert((rc = pthread_cond_signal(&cnd)) == 0); + +// assert(pthread_mutex_unlock(&mtx) == 0); + + assert(pthread_mutex_lock(&mtx) == 0); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + abstime.tv_sec += 1; + + assert((rc = pthread_cond_timedwait(&cnd, &mtx, &abstime)) == ETIMEDOUT); + + assert(pthread_mutex_unlock(&mtx) == 0); + + return 0; +} diff --git a/tests/condvar4.c b/tests/condvar4.c index 2b1a2d9..89fa855 100644 --- a/tests/condvar4.c +++ b/tests/condvar4.c @@ -1,169 +1,169 @@ -/* - * File: condvar4.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test PTHREAD_COND_INITIALIZER. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Test basic CV function but starting with a static initialised - * CV. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns 0. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -enum { - NUMTHREADS = 2 -}; - -void * -mythread(void * arg) -{ - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - cvthing.shared++; - - assert(pthread_cond_signal(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - cvthing.shared = 0; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); - - assert(cvthing.notbusy != PTHREAD_COND_INITIALIZER); - - assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - assert(cvthing.shared > 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - assert(pthread_mutex_destroy(&cvthing.lock) == 0); - - assert(cvthing.lock == NULL); - - assert(pthread_cond_destroy(&cvthing.notbusy) == 0); - - assert(cvthing.notbusy == NULL); - - return 0; -} +/* + * File: condvar4.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test PTHREAD_COND_INITIALIZER. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Test basic CV function but starting with a static initialised + * CV. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns 0. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +enum { + NUMTHREADS = 2 +}; + +void * +mythread(void * arg) +{ + assert(pthread_mutex_lock(&cvthing.lock) == 0); + cvthing.shared++; + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_cond_signal(&cvthing.notbusy) == 0); + + return (void *) 0; +} + +int +main() +{ + pthread_t t[NUMTHREADS]; + struct timespec abstime = { 0, 0 }; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + cvthing.shared = 0; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + + assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); + + assert(cvthing.notbusy != PTHREAD_COND_INITIALIZER); + + assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + assert(cvthing.shared > 0); + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_join(t[1], NULL) == 0); + + assert(pthread_mutex_destroy(&cvthing.lock) == 0); + + assert(cvthing.lock == NULL); + + assert(pthread_cond_destroy(&cvthing.notbusy) == 0); + + assert(cvthing.notbusy == NULL); + + return 0; +} diff --git a/tests/condvar5.c b/tests/condvar5.c index 3fb9591..4836676 100644 --- a/tests/condvar5.c +++ b/tests/condvar5.c @@ -1,168 +1,168 @@ -/* - * File: condvar5.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test pthread_cond_broadcast. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Test broadcast with one waiting CV. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - pthread_cond_timedwait returns 0. - * - Process returns zero exit status. - * - * Fail Criteria: - * - pthread_cond_timedwait returns ETIMEDOUT. - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -enum { - NUMTHREADS = 2 -}; - -void * -mythread(void * arg) -{ - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - cvthing.shared++; - - assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - pthread_t t[NUMTHREADS]; - struct timespec abstime = { 0, 0 }; - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - cvthing.shared = 0; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); - - /* get current system time */ - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); - - assert(cvthing.notbusy != PTHREAD_COND_INITIALIZER); - - assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - assert(cvthing.shared > 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - assert(pthread_mutex_destroy(&cvthing.lock) == 0); - - assert(cvthing.lock == NULL); - - assert(pthread_cond_destroy(&cvthing.notbusy) == 0); - - assert(cvthing.notbusy == NULL); - - return 0; -} +/* + * File: condvar5.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test pthread_cond_broadcast. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Test broadcast with one waiting CV. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - pthread_cond_timedwait returns 0. + * - Process returns zero exit status. + * + * Fail Criteria: + * - pthread_cond_timedwait returns ETIMEDOUT. + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +enum { + NUMTHREADS = 2 +}; + +void * +mythread(void * arg) +{ + assert(pthread_mutex_lock(&cvthing.lock) == 0); + cvthing.shared++; + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); + + return (void *) 0; +} + +int +main() +{ + pthread_t t[NUMTHREADS]; + struct timespec abstime = { 0, 0 }; + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + cvthing.shared = 0; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + + assert(cvthing.lock != PTHREAD_MUTEX_INITIALIZER); + + /* get current system time */ + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == ETIMEDOUT); + + assert(cvthing.notbusy != PTHREAD_COND_INITIALIZER); + + assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + assert(cvthing.shared > 0); + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_join(t[1], NULL) == 0); + + assert(pthread_mutex_destroy(&cvthing.lock) == 0); + + assert(cvthing.lock == NULL); + + assert(pthread_cond_destroy(&cvthing.notbusy) == 0); + + assert(cvthing.notbusy == NULL); + + return 0; +} diff --git a/tests/condvar6.c b/tests/condvar6.c index fc7a53b..1cb1d9e 100644 --- a/tests/condvar6.c +++ b/tests/condvar6.c @@ -1,241 +1,242 @@ -/* - * File: condvar6.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test pthread_cond_broadcast. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Test broadcast with NUMTHREADS (=5) waiting CVs. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - Process returns zero exit status. - * - * Fail Criteria: - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -/* - * Create NUMTHREADS threads in addition to the Main thread. - */ -enum { - NUMTHREADS = 5 -}; - -typedef struct bag_t_ bag_t; -struct bag_t_ { - int threadnum; - int started; - /* Add more per-thread state variables here */ -}; - -static bag_t threadbag[NUMTHREADS + 1]; - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; - -static struct timespec abstime = { 0, 0 }; - -static int awoken; - -void * -mythread(void * arg) -{ - bag_t * bag = (bag_t *) arg; - - assert(bag == &threadbag[bag->threadnum]); - assert(bag->started == 0); - bag->started = 1; - - /* Wait for the start gun */ - assert(pthread_mutex_lock(&start_flag) == 0); - assert(pthread_mutex_unlock(&start_flag) == 0); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - assert(cvthing.shared > 0); - - awoken++; - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - int failed = 0; - int i; - pthread_t t[NUMTHREADS + 1]; - - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - cvthing.shared = 0; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - assert(pthread_mutex_lock(&start_flag) == 0); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert((t[0] = pthread_self()).p != NULL); - - awoken = 0; - - for (i = 1; i <= NUMTHREADS; i++) - { - threadbag[i].started = 0; - threadbag[i].threadnum = i; - assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); - } - - /* - * Code to control or munipulate child threads should probably go here. - */ - - assert(pthread_mutex_unlock(&start_flag) == 0); - - /* - * Give threads time to start. - */ - Sleep(2000); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - cvthing.shared++; - - assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - /* - * Give threads time to complete. - */ - Sleep(2000); - - /* - * Cleanup the CV. - */ - - assert(pthread_mutex_destroy(&cvthing.lock) == 0); - - assert(cvthing.lock == NULL); - - assert(pthread_cond_destroy(&cvthing.notbusy) == 0); - - assert(cvthing.notbusy == NULL); - - /* - * 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); - } - } - - assert(!failed); - - /* - * Check any results here. - */ - - assert(awoken == NUMTHREADS); - - /* - * Success. - */ - return 0; -} - - +/* + * File: condvar6.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test pthread_cond_broadcast. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Test broadcast with NUMTHREADS (=5) waiting CVs. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 5 +}; + +typedef struct bag_t_ bag_t; +struct bag_t_ { + int threadnum; + int started; + /* Add more per-thread state variables here */ +}; + +static bag_t threadbag[NUMTHREADS + 1]; + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; + +static struct timespec abstime = { 0, 0 }; + +static int awoken; + +void * +mythread(void * arg) +{ + bag_t * bag = (bag_t *) arg; + + assert(bag == &threadbag[bag->threadnum]); + assert(bag->started == 0); + bag->started = 1; + + /* Wait for the start gun */ + assert(pthread_mutex_lock(&start_flag) == 0); + assert(pthread_mutex_unlock(&start_flag) == 0); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + assert(cvthing.shared > 0); + + awoken++; + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + return (void *) 0; +} + +int +main() +{ + int failed = 0; + int i; + pthread_t t[NUMTHREADS + 1]; + + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + cvthing.shared = 0; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + assert(pthread_mutex_lock(&start_flag) == 0); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert((t[0] = pthread_self()).p != NULL); + + awoken = 0; + + for (i = 1; i <= NUMTHREADS; i++) + { + threadbag[i].started = 0; + threadbag[i].threadnum = i; + assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); + } + + /* + * Code to control or munipulate child threads should probably go here. + */ + + assert(pthread_mutex_unlock(&start_flag) == 0); + + /* + * Give threads time to start. + */ + Sleep(1000); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + cvthing.shared++; + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); + + /* + * Give threads time to complete. + */ + for (i = 1; i <= NUMTHREADS; i++) + { + assert(pthread_join(t[i], NULL) == 0); + } + + /* + * Cleanup the CV. + */ + + assert(pthread_mutex_destroy(&cvthing.lock) == 0); + + assert(cvthing.lock == NULL); + + assert(pthread_cond_destroy(&cvthing.notbusy) == 0); + + assert(cvthing.notbusy == NULL); + + /* + * 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); + } + } + + assert(!failed); + + /* + * Check any results here. + */ + + assert(awoken == NUMTHREADS); + + /* + * Success. + */ + return 0; +} + + diff --git a/tests/condvar7.c b/tests/condvar7.c index aa9b070..696a18e 100644 --- a/tests/condvar7.c +++ b/tests/condvar7.c @@ -1,259 +1,257 @@ -/* - * File: condvar7.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test pthread_cond_broadcast with thread cancelation. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Test broadcast with NUMTHREADS (=5) waiting CVs, one is canceled while waiting. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - Process returns zero exit status. - * - * Fail Criteria: - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -/* - * Create NUMTHREADS threads in addition to the Main thread. - */ -enum { - NUMTHREADS = 5 -}; - -typedef struct bag_t_ bag_t; -struct bag_t_ { - int threadnum; - int started; - /* Add more per-thread state variables here */ -}; - -static bag_t threadbag[NUMTHREADS + 1]; - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; - -static struct timespec abstime = { 0, 0 }; - -static int awoken; - -void * -mythread(void * arg) -{ - bag_t * bag = (bag_t *) arg; - - assert(bag == &threadbag[bag->threadnum]); - assert(bag->started == 0); - bag->started = 1; - - /* Wait for the start gun */ - assert(pthread_mutex_lock(&start_flag) == 0); - assert(pthread_mutex_unlock(&start_flag) == 0); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - -#ifdef _MSC_VER -#pragma inline_depth(0) -#endif - pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - pthread_cleanup_pop(0); -#ifdef _MSC_VER -#pragma inline_depth() -#endif - - assert(cvthing.shared > 0); - - awoken++; - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - int failed = 0; - int i; - pthread_t t[NUMTHREADS + 1]; - - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - cvthing.shared = 0; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - assert(pthread_mutex_lock(&start_flag) == 0); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 10; - - assert((t[0] = pthread_self()).p != NULL); - - awoken = 0; - - for (i = 1; i <= NUMTHREADS; i++) - { - threadbag[i].started = 0; - threadbag[i].threadnum = i; - assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); - } - - /* - * Code to control or munipulate child threads should probably go here. - */ - - assert(pthread_mutex_unlock(&start_flag) == 0); - - /* - * Give threads time to start. - */ - Sleep(1000); - - /* - * Cancel one of the threads. - */ - assert(pthread_cancel(t[1]) == 0); - assert(pthread_join(t[1], NULL) == 0); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - cvthing.shared++; - - /* - * Signal all remaining waiting threads. - */ - assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - /* - * Wait for all threads to complete. - */ - for (i = 2; i <= NUMTHREADS; i++) - assert(pthread_join(t[i], NULL) == 0); - - /* - * Cleanup the CV. - */ - - assert(pthread_mutex_destroy(&cvthing.lock) == 0); - - assert(cvthing.lock == NULL); - - assert(pthread_cond_destroy(&cvthing.notbusy) == 0); - - assert(cvthing.notbusy == NULL); - - /* - * 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); - } - } - - assert(!failed); - - /* - * Check any results here. - */ - - assert(awoken == (NUMTHREADS - 1)); - - /* - * Success. - */ - return 0; -} +/* + * File: condvar7.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test pthread_cond_broadcast with thread cancelation. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Test broadcast with NUMTHREADS (=5) waiting CVs, one is canceled while waiting. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 5 +}; + +typedef struct bag_t_ bag_t; +struct bag_t_ { + int threadnum; + int started; + /* Add more per-thread state variables here */ +}; + +static bag_t threadbag[NUMTHREADS + 1]; + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; + +static struct timespec abstime = { 0, 0 }; + +static int awoken; + +void * +mythread(void * arg) +{ + bag_t * bag = (bag_t *) arg; + + assert(bag == &threadbag[bag->threadnum]); + assert(bag->started == 0); + bag->started = 1; + + /* Wait for the start gun */ + assert(pthread_mutex_lock(&start_flag) == 0); + assert(pthread_mutex_unlock(&start_flag) == 0); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + +#ifdef _MSC_VER +#pragma inline_depth(0) +#endif + pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + pthread_cleanup_pop(0); +#ifdef _MSC_VER +#pragma inline_depth() +#endif + + assert(cvthing.shared > 0); + + awoken++; + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + return (void *) 0; +} + +int +main() +{ + int failed = 0; + int i; + pthread_t t[NUMTHREADS + 1]; + + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + cvthing.shared = 0; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + assert(pthread_mutex_lock(&start_flag) == 0); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 10; + + assert((t[0] = pthread_self()).p != NULL); + + awoken = 0; + + for (i = 1; i <= NUMTHREADS; i++) + { + threadbag[i].started = 0; + threadbag[i].threadnum = i; + assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); + } + + /* + * Code to control or munipulate child threads should probably go here. + */ + + assert(pthread_mutex_unlock(&start_flag) == 0); + + /* + * Give threads time to start. + */ + Sleep(1000); + + /* + * Cancel one of the threads. + */ + assert(pthread_cancel(t[1]) == 0); + assert(pthread_join(t[1], NULL) == 0); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + cvthing.shared++; + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + /* + * Signal all remaining waiting threads. + */ + assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); + + /* + * Wait for all threads to complete. + */ + for (i = 2; i <= NUMTHREADS; i++) + assert(pthread_join(t[i], NULL) == 0); + + /* + * Cleanup the CV. + */ + + assert(pthread_mutex_destroy(&cvthing.lock) == 0); + + assert(cvthing.lock == NULL); + + assert(pthread_cond_destroy(&cvthing.notbusy) == 0); + + assert(cvthing.notbusy == NULL); + + /* + * 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); + } + } + + assert(!failed); + + /* + * Check any results here. + */ + + assert(awoken == (NUMTHREADS - 1)); + + /* + * Success. + */ + return 0; +} diff --git a/tests/condvar8.c b/tests/condvar8.c index bbab906..890970e 100644 --- a/tests/condvar8.c +++ b/tests/condvar8.c @@ -1,258 +1,258 @@ -/* - * File: condvar8.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test multiple pthread_cond_broadcasts. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Make NUMTHREADS threads wait on CV, broadcast signal them, and then repeat. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - Process returns zero exit status. - * - * Fail Criteria: - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -/* - * Create NUMTHREADS threads in addition to the Main thread. - */ -enum { - NUMTHREADS = 5 -}; - -typedef struct bag_t_ bag_t; -struct bag_t_ { - int threadnum; - int started; - /* Add more per-thread state variables here */ -}; - -static bag_t threadbag[NUMTHREADS + 1]; - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; - -static struct timespec abstime = { 0, 0 }; - -static int awoken; - -static void * -mythread(void * arg) -{ - bag_t * bag = (bag_t *) arg; - - assert(bag == &threadbag[bag->threadnum]); - assert(bag->started == 0); - bag->started = 1; - - /* Wait for the start gun */ - assert(pthread_mutex_lock(&start_flag) == 0); - assert(pthread_mutex_unlock(&start_flag) == 0); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - -#ifdef _MSC_VER -#pragma inline_depth(0) -#endif - pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - pthread_cleanup_pop(0); -#ifdef _MSC_VER -#pragma inline_depth() -#endif - - assert(cvthing.shared > 0); - - awoken++; - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - int failed = 0; - int i; - int first, last; - pthread_t t[NUMTHREADS + 1]; - - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 10; - - assert((t[0] = pthread_self()).p != NULL); - - awoken = 0; - - for (first = 1, last = NUMTHREADS / 2; - first < NUMTHREADS; - first = last + 1, last = NUMTHREADS) - { - assert(pthread_mutex_lock(&start_flag) == 0); - - for (i = first; i <= last; i++) - { - threadbag[i].started = 0; - threadbag[i].threadnum = i; - assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); - assert(pthread_detach(t[i]) == 0); - } - - /* - * Code to control or munipulate child threads should probably go here. - */ - cvthing.shared = 0; - - assert(pthread_mutex_unlock(&start_flag) == 0); - - /* - * Give threads time to start. - */ - Sleep(1000); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - cvthing.shared++; - - assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - /* - * Give threads time to complete. - */ - Sleep(1000); - - assert(awoken == (i - 1)); - } - - - /* - * 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); - } - } - - /* - * Cleanup the CV. - */ - - assert(pthread_mutex_destroy(&cvthing.lock) == 0); - - assert(cvthing.lock == NULL); - - assert(pthread_cond_destroy(&cvthing.notbusy) == 0); - - assert(cvthing.notbusy == NULL); - - assert(!failed); - - /* - * Check any results here. - */ - - assert(awoken == NUMTHREADS); - - /* - * Success. - */ - return 0; -} +/* + * File: condvar8.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test multiple pthread_cond_broadcasts. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Make NUMTHREADS threads wait on CV, broadcast signal them, and then repeat. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 5 +}; + +typedef struct bag_t_ bag_t; +struct bag_t_ { + int threadnum; + int started; + /* Add more per-thread state variables here */ +}; + +static bag_t threadbag[NUMTHREADS + 1]; + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; + +static struct timespec abstime = { 0, 0 }; + +static int awoken; + +static void * +mythread(void * arg) +{ + bag_t * bag = (bag_t *) arg; + + assert(bag == &threadbag[bag->threadnum]); + assert(bag->started == 0); + bag->started = 1; + + /* Wait for the start gun */ + assert(pthread_mutex_lock(&start_flag) == 0); + assert(pthread_mutex_unlock(&start_flag) == 0); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + +#ifdef _MSC_VER +#pragma inline_depth(0) +#endif + pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + pthread_cleanup_pop(0); +#ifdef _MSC_VER +#pragma inline_depth() +#endif + + assert(cvthing.shared > 0); + + awoken++; + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + return (void *) 0; +} + +int +main() +{ + int failed = 0; + int i; + int first, last; + pthread_t t[NUMTHREADS + 1]; + + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 10; + + assert((t[0] = pthread_self()).p != NULL); + + awoken = 0; + + for (first = 1, last = NUMTHREADS / 2; + first < NUMTHREADS; + first = last + 1, last = NUMTHREADS) + { + assert(pthread_mutex_lock(&start_flag) == 0); + + for (i = first; i <= last; i++) + { + threadbag[i].started = 0; + threadbag[i].threadnum = i; + assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); + } + + /* + * Code to control or munipulate child threads should probably go here. + */ + cvthing.shared = 0; + + assert(pthread_mutex_unlock(&start_flag) == 0); + + /* + * Give threads time to start. + */ + Sleep(100); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + cvthing.shared++; + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); + + /* + * Give threads time to complete. + */ + for (i = first; i <= last; i++) + { + assert(pthread_join(t[i], NULL) == 0); + } + + assert(awoken == (i - 1)); + } + + + /* + * 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); + } + } + + /* + * Cleanup the CV. + */ + + assert(pthread_mutex_destroy(&cvthing.lock) == 0); + + assert(cvthing.lock == NULL); + + assert(pthread_cond_destroy(&cvthing.notbusy) == 0); + + assert(cvthing.notbusy == NULL); + + assert(!failed); + + /* + * Check any results here. + */ + + assert(awoken == NUMTHREADS); + + /* + * Success. + */ + return 0; +} diff --git a/tests/condvar9.c b/tests/condvar9.c index cdeced2..6610af7 100644 --- a/tests/condvar9.c +++ b/tests/condvar9.c @@ -1,269 +1,267 @@ -/* - * File: condvar9.c - * - * - * -------------------------------------------------------------------------- - * - * Pthreads-win32 - POSIX Threads Library for Win32 - * Copyright(C) 1998 John E. Bossom - * Copyright(C) 1999,2005 Pthreads-win32 contributors - * - * Contact Email: rpj@callisto.canberra.edu.au - * - * The current list of contributors is contained - * in the file CONTRIBUTORS included with the source - * code distribution. The list can also be seen at the - * following World Wide Web location: - * http://sources.redhat.com/pthreads-win32/contributors.html - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library in the file COPYING.LIB; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test Synopsis: - * - Test multiple pthread_cond_broadcasts with thread cancelation. - * - * Test Method (Validation or Falsification): - * - Validation - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - Make NUMTHREADS threads wait on CV, cancel one, broadcast signal them, - * and then repeat. - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - - * - * Pass Criteria: - * - Process returns zero exit status. - * - * Fail Criteria: - * - Process returns non-zero exit status. - */ - -#include "test.h" -#include - -/* - * Create NUMTHREADS threads in addition to the Main thread. - */ -enum { - NUMTHREADS = 9 -}; - -typedef struct bag_t_ bag_t; -struct bag_t_ { - int threadnum; - int started; - int finished; - /* Add more per-thread state variables here */ -}; - -static bag_t threadbag[NUMTHREADS + 1]; - -typedef struct cvthing_t_ cvthing_t; - -struct cvthing_t_ { - pthread_cond_t notbusy; - pthread_mutex_t lock; - int shared; -}; - -static cvthing_t cvthing = { - PTHREAD_COND_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - 0 -}; - -static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; - -static struct timespec abstime = { 0, 0 }; - -static int awoken; - -static void * -mythread(void * arg) -{ - bag_t * bag = (bag_t *) arg; - - assert(bag == &threadbag[bag->threadnum]); - assert(bag->started == 0); - bag->started = 1; - - /* Wait for the start gun */ - assert(pthread_mutex_lock(&start_flag) == 0); - assert(pthread_mutex_unlock(&start_flag) == 0); - - assert(pthread_mutex_lock(&cvthing.lock) == 0); - - /* - * pthread_cond_timedwait is a cancelation point and we're - * going to cancel some threads deliberately. - */ -#ifdef _MSC_VER -#pragma inline_depth(0) -#endif - pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); - - while (! (cvthing.shared > 0)) - assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); - - pthread_cleanup_pop(0); -#ifdef _MSC_VER -#pragma inline_depth() -#endif - - assert(cvthing.shared > 0); - - awoken++; - bag->finished = 1; - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - return (void *) 0; -} - -int -main() -{ - int failed = 0; - int i; - int first, last; - int canceledThreads = 0; - pthread_t t[NUMTHREADS + 1]; - - struct _timeb currSysTime; - const DWORD NANOSEC_PER_MILLISEC = 1000000; - - assert((t[0] = pthread_self()).p != NULL); - - assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); - - assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); - - _ftime(&currSysTime); - - abstime.tv_sec = currSysTime.time; - abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; - - abstime.tv_sec += 5; - - assert((t[0] = pthread_self()).p != NULL); - - awoken = 0; - - for (first = 1, last = NUMTHREADS / 2; - 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 = threadbag[i].finished = 0; - threadbag[i].threadnum = i; - assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); - } - - /* - * Code to control or munipulate child threads should probably go here. - */ - cvthing.shared = 0; - - assert(pthread_mutex_unlock(&start_flag) == 0); - - /* - * Give threads time to start. - */ - 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_cond_broadcast(&cvthing.notbusy) == 0); - - assert(pthread_mutex_unlock(&cvthing.lock) == 0); - - /* - * Standard check that all threads started - and wait for them to finish. - */ - 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_e(pthread_cond_destroy(&cvthing.notbusy), ==, 0); - - assert(cvthing.notbusy == NULL); - - assert(!failed); - - /* - * Check any results here. - */ - - assert(awoken == NUMTHREADS - canceledThreads); - - /* - * Success. - */ - return 0; -} +/* + * File: condvar9.c + * + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * -------------------------------------------------------------------------- + * + * Test Synopsis: + * - Test multiple pthread_cond_broadcasts with thread cancelation. + * + * Test Method (Validation or Falsification): + * - Validation + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - Make NUMTHREADS threads wait on CV, cancel one, broadcast signal them, + * and then repeat. + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#include "test.h" +#include + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 9 +}; + +typedef struct bag_t_ bag_t; +struct bag_t_ { + int threadnum; + int started; + int finished; + /* Add more per-thread state variables here */ +}; + +static bag_t threadbag[NUMTHREADS + 1]; + +typedef struct cvthing_t_ cvthing_t; + +struct cvthing_t_ { + pthread_cond_t notbusy; + pthread_mutex_t lock; + int shared; +}; + +static cvthing_t cvthing = { + PTHREAD_COND_INITIALIZER, + PTHREAD_MUTEX_INITIALIZER, + 0 +}; + +static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER; + +static struct timespec abstime = { 0, 0 }; + +static int awoken; + +static void * +mythread(void * arg) +{ + bag_t * bag = (bag_t *) arg; + + assert(bag == &threadbag[bag->threadnum]); + assert(bag->started == 0); + bag->started = 1; + + /* Wait for the start gun */ + assert(pthread_mutex_lock(&start_flag) == 0); + assert(pthread_mutex_unlock(&start_flag) == 0); + + assert(pthread_mutex_lock(&cvthing.lock) == 0); + + /* + * pthread_cond_timedwait is a cancelation point and we're + * going to cancel some threads deliberately. + */ +#ifdef _MSC_VER +#pragma inline_depth(0) +#endif + pthread_cleanup_push(pthread_mutex_unlock, (void *) &cvthing.lock); + + while (! (cvthing.shared > 0)) + assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0); + + pthread_cleanup_pop(0); +#ifdef _MSC_VER +#pragma inline_depth() +#endif + + assert(cvthing.shared > 0); + + awoken++; + bag->finished = 1; + + assert(pthread_mutex_unlock(&cvthing.lock) == 0); + + return (void *) 0; +} + +int +main() +{ + int failed = 0; + int i; + int first, last; + int canceledThreads = 0; + pthread_t t[NUMTHREADS + 1]; + + struct _timeb currSysTime; + const DWORD NANOSEC_PER_MILLISEC = 1000000; + + assert((t[0] = pthread_self()).p != NULL); + + assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER); + + assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER); + + _ftime(&currSysTime); + + abstime.tv_sec = currSysTime.time; + abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; + + abstime.tv_sec += 5; + + assert((t[0] = pthread_self()).p != NULL); + + awoken = 0; + + for (first = 1, last = NUMTHREADS / 2; + 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 = threadbag[i].finished = 0; + threadbag[i].threadnum = i; + assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); + } + + /* + * Code to control or munipulate child threads should probably go here. + */ + cvthing.shared = 0; + + assert(pthread_mutex_unlock(&start_flag) == 0); + + /* + * Give threads time to start. + */ + 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_mutex_unlock(&cvthing.lock) == 0); + + assert(pthread_cond_broadcast(&cvthing.notbusy) == 0); + + /* + * Standard check that all threads started - and wait for them to finish. + */ + 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_e(pthread_cond_destroy(&cvthing.notbusy), ==, 0); + + assert(cvthing.notbusy == NULL); + + assert(!failed); + + /* + * Check any results here. + */ + + assert(awoken == NUMTHREADS - canceledThreads); + + /* + * Success. + */ + return 0; +} -- cgit v1.2.3