From 30a1e9738593302fa26e0a668f517bc7f5800190 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 13 Jan 2002 02:29:40 +0000 Subject: * attr.c (pthread_attr_setscope): Fix struct pointer indirection error introduced 2002-01-04. (pthread_attr_getscope): Likewise. * pthread.dsp (SOURCE): Add missing source files. ./tests/: * exception3.c (main): Shorten wait time. * mutex7.c: New test. * mutex7n.c: New test. * mutex7e.c: New test. * mutex7r.c: New test. * mutex6.c: Modified to avoid leaving the locked mutex around on exit. --- ChangeLog | 10 ++++++ Nmakefile.tests | 13 ++++++++ attr.c | 4 +-- pthread.dsp | 12 +++++++ tests/ChangeLog | 13 ++++++++ tests/GNUmakefile | 9 ++++++ tests/Makefile | 9 ++++++ tests/exception3.c | 4 +-- tests/mutex6.c | 18 ++++++++--- tests/mutex6n.c | 15 +++++++-- tests/mutex7.c | 73 ++++++++++++++++++++++++++++++++++++++++++ tests/mutex7e.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/mutex7n.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/mutex7r.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 438 insertions(+), 10 deletions(-) create mode 100644 tests/mutex7.c create mode 100644 tests/mutex7e.c create mode 100644 tests/mutex7n.c create mode 100644 tests/mutex7r.c diff --git a/ChangeLog b/ChangeLog index a3e1403..dede9f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-01-14 Ross Johnson + + * attr.c (pthread_attr_setscope): Fix struct pointer + indirection error introduced 2002-01-04. + (pthread_attr_getscope): Likewise. + +2002-01-12 Ross Johnson + + * pthread.dsp (SOURCE): Add missing source files. + 2002-01-08 Ross Johnson * mutex.c (pthread_mutex_trylock): use diff --git a/Nmakefile.tests b/Nmakefile.tests index a99b1db..2427bf9 100644 --- a/Nmakefile.tests +++ b/Nmakefile.tests @@ -42,6 +42,10 @@ mutex6:: mutex6.c mutex6e:: mutex6e.c mutex6n:: mutex6n.c mutex6r:: mutex6r.c +mutex7:: mutex7.c +mutex7e:: mutex7e.c +mutex7n:: mutex7n.c +mutex7r:: mutex7r.c equal1:: equal1.c exit2:: exit2.c exit3:: exit3.c @@ -98,6 +102,7 @@ benchtest4:: benchtest4.c benchtest5:: benchtest5.c loadfree: :test: +mutex5 :test: loadfree mutex1 :test: loadfree mutex2 :test: loadfree exit1 :test: loadfree @@ -110,6 +115,14 @@ cancel1 :test: create1 cancel2 :test: cancel1 mutex3 :test: create1 mutex4 :test: mutex3 +mutex6 :test: mutex4 +mutex6n :test: mutex4 +mutex6e :test: mutex4 +mutex6r :test: mutex4 +mutex7 :test: mutex6 +mutex7n :test: mutex6n +mutex7e :test: mutex6e +mutex7r :test: mutex6r equal1 :test: create1 exit2 :test: create1 exit3 :test: create1 diff --git a/attr.c b/attr.c index 21c3ddb..5a76403 100644 --- a/attr.c +++ b/attr.c @@ -518,7 +518,7 @@ pthread_attr_setscope(pthread_attr_t *attr, int contentionscope) #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING switch (contentionscope) { case PTHREAD_SCOPE_SYSTEM: - attr->contentionscope = contentionscope; + (*attr)->contentionscope = contentionscope; return 0; case PTHREAD_SCOPE_PROCESS: return ENOTSUP; @@ -535,7 +535,7 @@ int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope) { #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING - *contentionscope = attr->contentionscope; + *contentionscope = (*attr)->contentionscope; return 0; #else return ENOSYS; diff --git a/pthread.dsp b/pthread.dsp index 5706f6d..e6b44b3 100644 --- a/pthread.dsp +++ b/pthread.dsp @@ -96,6 +96,12 @@ SOURCE=.\attr.c # End Source File # Begin Source File +SOURCE=.\barrier.c +# End Source File +# Begin Source File + +# Begin Source File + SOURCE=.\cancel.c # End Source File # Begin Source File @@ -156,6 +162,12 @@ SOURCE=.\signal.c # End Source File # Begin Source File +SOURCE=.\spin.c +# End Source File +# Begin Source File + +# Begin Source File + SOURCE=.\sync.c # End Source File # Begin Source File diff --git a/tests/ChangeLog b/tests/ChangeLog index 77d81db..ce460e7 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,16 @@ +2002-01-14 Ross Johnson + + * exception3.c (main): Shorten wait time. + +2002-01-09 Ross Johnson + + * mutex7.c: New test. + * mutex7n.c: New test. + * mutex7e.c: New test. + * mutex7r.c: New test. + * mutex6.c: Modified to avoid leaving the locked mutex + around on exit. + 2001-10-25 Ross Johnson * condvar2.c: Remove reference to cv->nWaitersUnblocked. diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 8e06c68..26b707c 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -40,6 +40,7 @@ TESTS = loadfree \ condvar1 condvar2 condvar2_1 exit1 create1 equal1 \ exit2 exit3 \ join0 join1 join2 mutex2 mutex3 mutex4 mutex6 mutex6n mutex6e mutex6r \ + mutex7 mutex7n mutex7e mutex7r \ count1 once1 tsd1 self2 cancel1 cancel2 eyal1 \ condvar3 condvar3_1 condvar3_2 condvar3_3 \ condvar4 condvar5 condvar6 condvar7 condvar8 condvar9 \ @@ -146,6 +147,14 @@ mutex2.pass: mutex1.pass mutex3.pass: create1.pass mutex4.pass: mutex3.pass mutex5.pass: +mutex6.pass: mutex4.pass +mutex6n.pass: mutex4.pass +mutex6e.pass: mutex4.pass +mutex6r.pass: mutex4.pass +mutex7.pass: mutex6.pass +mutex7n.pass: mutex6n.pass +mutex7e.pass: mutex6e.pass +mutex7r.pass: mutex6r.pass once1.pass: create1.pass priority1.pass: join1.pass priority2.pass: priority1.pass diff --git a/tests/Makefile b/tests/Makefile index 1a7b6bf..9eade03 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -44,6 +44,7 @@ PASSES= loadfree.pass \ exit2.pass exit3.pass \ join0.pass join1.pass join2.pass \ mutex4.pass mutex6.pass mutex6n.pass mutex6e.pass mutex6r.pass \ + mutex7.pass mutex7n.pass mutex7e.pass mutex7r.pass \ count1.pass once1.pass tsd1.pass \ self2.pass \ cancel1.pass cancel2.pass \ @@ -200,6 +201,14 @@ mutex2.pass: mutex1.pass mutex3.pass: create1.pass mutex4.pass: mutex3.pass mutex5.pass: +mutex6.pass: mutex4.pass +mutex6n.pass: mutex4.pass +mutex6e.pass: mutex4.pass +mutex6r.pass: mutex4.pass +mutex7.pass: mutex6.pass +mutex7n.pass: mutex6n.pass +mutex7e.pass: mutex6e.pass +mutex7r.pass: mutex6r.pass once1.pass: create1.pass priority1.pass: join1.pass priority2.pass: priority1.pass diff --git a/tests/exception3.c b/tests/exception3.c index bb27ff7..08f88a7 100644 --- a/tests/exception3.c +++ b/tests/exception3.c @@ -87,7 +87,7 @@ terminateFunction () { pthread_mutex_lock(&caughtLock); caught++; -#if 0 +#if 1 { FILE * fp = fopen("pthread.log", "a"); fprintf(fp, "Caught = %d\n", caught); @@ -123,7 +123,7 @@ main() assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); } - Sleep(10000); + Sleep(5000); assert(caught == NUMTHREADS); diff --git a/tests/mutex6.c b/tests/mutex6.c index 5cd6d46..dc14c46 100644 --- a/tests/mutex6.c +++ b/tests/mutex6.c @@ -45,10 +45,10 @@ void * locker(void * arg) { assert(pthread_mutex_lock(&mutex) == 0); lockCount++; - assert(pthread_mutex_lock(&mutex) != 0); + + /* Should wait here (deadlocked) */ + assert(pthread_mutex_lock(&mutex) == 0); lockCount++; - Sleep(1000); - assert(pthread_mutex_unlock(&mutex) == 0); assert(pthread_mutex_unlock(&mutex) == 0); return 0; @@ -63,10 +63,20 @@ main() assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(2000); + Sleep(1000); assert(lockCount == 1); + /* + * Should succeed even though we don't own the lock + * because FAST mutexes don't check ownership. + */ + assert(pthread_mutex_unlock(&mutex) == 0); + + Sleep (1000); + + assert(lockCount == 2); + exit(0); /* Never reached */ diff --git a/tests/mutex6n.c b/tests/mutex6n.c index d982c4c..e006f24 100644 --- a/tests/mutex6n.c +++ b/tests/mutex6n.c @@ -49,10 +49,11 @@ void * locker(void * arg) { assert(pthread_mutex_lock(&mutex) == 0); lockCount++; - assert(pthread_mutex_lock(&mutex) != 0); + + /* Should wait here (deadlocked) */ + assert(pthread_mutex_lock(&mutex) == 0); lockCount++; assert(pthread_mutex_unlock(&mutex) == 0); - assert(pthread_mutex_unlock(&mutex) == 0); return (void *) 555; } @@ -76,6 +77,16 @@ main() assert(lockCount == 1); + /* + * Should succeed even though we don't own the lock + * because FAST mutexes don't check ownership. + */ + assert(pthread_mutex_unlock(&mutex) == 0); + + Sleep (1000); + + assert(lockCount == 2); + exit(0); /* Never reached */ diff --git a/tests/mutex7.c b/tests/mutex7.c new file mode 100644 index 0000000..9b0c9d0 --- /dev/null +++ b/tests/mutex7.c @@ -0,0 +1,73 @@ +/* + * mutex7.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- + * + * Test the default (type not set) mutex type. + * Should be the same as PTHREAD_MUTEX_NORMAL. + * Thread locks then trylocks mutex (attempted recursive lock). + * The thread should lock first time and EBUSY second time. + * + * Depends on API functions: + * pthread_mutex_lock() + * pthread_mutex_trylock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; + +void * locker(void * arg) +{ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_trylock(&mutex) == EBUSY); + lockCount++; + assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(&mutex) == EPERM); + + return 0; +} + +int +main() +{ + pthread_t t; + + assert(pthread_mutex_init(&mutex, NULL) == 0); + + assert(pthread_create(&t, NULL, locker, NULL) == 0); + + Sleep(1000); + + assert(lockCount == 2); + + exit(0); + + /* Never reached */ + return 0; +} diff --git a/tests/mutex7e.c b/tests/mutex7e.c new file mode 100644 index 0000000..95b339c --- /dev/null +++ b/tests/mutex7e.c @@ -0,0 +1,93 @@ +/* + * mutex7e.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_ERRORCHECK mutex type. + * Thread locks and then trylocks mutex (attempted recursive lock). + * Trylock should fail with an EDEADLK error. + * The second unlock attempt should fail with an EPERM error. + * + * Depends on API functions: + * pthread_create() + * pthread_join() + * pthread_mutexattr_init() + * pthread_mutexattr_destroy() + * pthread_mutexattr_settype() + * pthread_mutexattr_gettype() + * pthread_mutex_init() + * pthread_mutex_destroy() + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_trylock(&mutex) == EDEADLK); + lockCount++; + assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(&mutex) == EPERM); + + return (void *) 555; +} + +int +main() +{ + pthread_t t; + int result = 0; + int mxType = -1; + + assert(pthread_mutexattr_init(&mxAttr) == 0); + assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0); + assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); + assert(mxType == PTHREAD_MUTEX_ERRORCHECK); + + assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + + assert(pthread_create(&t, NULL, locker, NULL) == 0); + + assert(pthread_join(t, (void **) &result) == 0); + assert(result == 555); + + assert(lockCount == 2); + + assert(pthread_mutex_destroy(&mutex) == 0); + assert(pthread_mutexattr_destroy(&mxAttr) == 0); + + exit(0); + + /* Never reached */ + return 0; +} + diff --git a/tests/mutex7n.c b/tests/mutex7n.c new file mode 100644 index 0000000..d3f2206 --- /dev/null +++ b/tests/mutex7n.c @@ -0,0 +1,84 @@ +/* + * mutex7n.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_NORMAL mutex type. + * Thread locks then trylocks mutex (attempted recursive lock). + * The thread should lock first time and EBUSY second time. + * + * Depends on API functions: + * pthread_create() + * pthread_mutexattr_init() + * pthread_mutexattr_settype() + * pthread_mutexattr_gettype() + * pthread_mutex_init() + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_trylock(&mutex) == EBUSY); + lockCount++; + assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(&mutex) == EPERM); + + return (void *) 555; +} + +int +main() +{ + pthread_t t; + int mxType = -1; + + assert(pthread_mutexattr_init(&mxAttr) == 0); + assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0); + assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); + assert(mxType == PTHREAD_MUTEX_NORMAL); + + assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + + assert(pthread_create(&t, NULL, locker, NULL) == 0); + + Sleep(1000); + + assert(lockCount == 2); + + exit(0); + + /* Never reached */ + return 0; +} + diff --git a/tests/mutex7r.c b/tests/mutex7r.c new file mode 100644 index 0000000..febac75 --- /dev/null +++ b/tests/mutex7r.c @@ -0,0 +1,91 @@ +/* + * mutex7r.c + * + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright (C) 1998 Ben Elliston and Ross Johnson + * Copyright (C) 1999,2000,2001 Ross Johnson + * + * Contact Email: rpj@ise.canberra.edu.au + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- + * + * Tests PTHREAD_MUTEX_RECURSIVE mutex type. + * Thread locks mutex then trylocks mutex (recursive lock twice). + * Both locks and unlocks should succeed. + * + * Depends on API functions: + * pthread_create() + * pthread_join() + * pthread_mutexattr_init() + * pthread_mutexattr_destroy() + * pthread_mutexattr_settype() + * pthread_mutexattr_gettype() + * pthread_mutex_init() + * pthread_mutex_destroy() + * pthread_mutex_lock() + * pthread_mutex_unlock() + */ + +#include "test.h" + +static int lockCount = 0; + +static pthread_mutex_t mutex; +static pthread_mutexattr_t mxAttr; + +void * locker(void * arg) +{ + assert(pthread_mutex_lock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_trylock(&mutex) == 0); + lockCount++; + assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(&mutex) == 0); + + return (void *) 555; +} + +int +main() +{ + pthread_t t; + int result = 0; + int mxType = -1; + + assert(pthread_mutexattr_init(&mxAttr) == 0); + assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0); + assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); + assert(mxType == PTHREAD_MUTEX_RECURSIVE); + + assert(pthread_mutex_init(&mutex, &mxAttr) == 0); + + assert(pthread_create(&t, NULL, locker, NULL) == 0); + + assert(pthread_join(t, (void **) &result) == 0); + assert(result == 555); + + assert(lockCount == 2); + + assert(pthread_mutex_destroy(&mutex) == 0); + assert(pthread_mutexattr_destroy(&mxAttr) == 0); + + exit(0); + + /* Never reached */ + return 0; +} -- cgit v1.2.3