summaryrefslogtreecommitdiff
path: root/tests/mutex4.c
diff options
context:
space:
mode:
authorrpj <rpj>2000-12-29 07:08:44 +0000
committerrpj <rpj>2000-12-29 07:08:44 +0000
commit0c2cb3fb140fb0d12586587001cb1ca238cf8c25 (patch)
tree72caf359f0e3d2aea2c833c8061b65f971f91381 /tests/mutex4.c
parentbab1896412f2d292ebd8d44bc9d6ddb58a8702b0 (diff)
./ChangeLog:
2000-12-29 Ross Johnson <rpj@special.ise.canberra.edu.au> * Makefile: Back-out "for" loops which don't work. * GNUmakefile: Remove the fake.a target; add the "realclean" target; don't remove built libs under the "clean" target. * config.h: Add a guard against multiple inclusion. * semaphore.h: Add some defines from config.h to make semaphore.h independent of config.h when building apps. * pthread.h (_errno): Back-out previous fix until we know how to fix it properly. * implement.h (lockCount): Add missing element to pthread_mutex_t_. * sync.c (pthread_join): Spelling fix in comment. * private.c (ptw32_threadStart): Reset original termination function (C++). (ptw32_threadStart): Cleanup detached threads early in case the library is statically linked. (ptw32_callUserDestroyRoutines): Remove [SEH] __try block from destructor call so that unhandled exceptions will be passed through to the system; call terminate() from [C++] try block for the same reason. * tsd.c (pthread_getspecific): Add comment. * mutex.c (pthread_mutex_init): Initialise new elements in pthread_mutex_t. (pthread_mutex_unlock): Invert "pthread_equal()" test. 2000-12-28 Ross Johnson <rpj@special.ise.canberra.edu.au> * semaphore.c (mode_t): Use ifndef HAVE_MODE_T to include definition. * config.h.in (HAVE_MODE_T): Added. (_UWIN): Start adding defines for the UWIN package. ./tests/ChangeLog: 2000-12-29 Ross Johnson <rpj@special.ise.canberra.edu.au> * GNUmakefile: Add mutex4 test; ensure libpthreadw32.a is removed for "clean" target. * Makefile: Add mutex4 test. * exception3.c: Remove SEH code; automatically pass the test under SEH (which is an N/A environment). * mutex4.c: New test. * eyal1.c (do_work_unit): Add a dummy "if" to force the optimiser to retain code; reduce thread work loads. * condvar8.c (main): Add an additional "assert" for debugging; increase pthread_cond_signal timeout.
Diffstat (limited to 'tests/mutex4.c')
-rw-r--r--tests/mutex4.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/tests/mutex4.c b/tests/mutex4.c
index 5290f2a..7b989d0 100644
--- a/tests/mutex4.c
+++ b/tests/mutex4.c
@@ -10,35 +10,32 @@
*/
#include "test.h"
-
-pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t locker_done = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t unlocker_done = PTHREAD_MUTEX_INITIALIZER;
-static int washere = 0;
+static int wasHere = 0;
+
+static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
void * locker(void * arg)
{
- assert(pthread_mutex_lock(&locker_start) == 0);
+ wasHere++;
assert(pthread_mutex_lock(&mutex1) == 0);
- assert(pthread_mutex_unlock(&locker_start) == 0);
-
- /* Wait for unlocker to finish */
- assert(pthread_mutex_lock(&unlocker_end) == 0);
+ Sleep(1000);
assert(pthread_mutex_unlock(&mutex1) == 0);
+ wasHere++;
return 0;
}
void * unlocker(void * arg)
{
+ wasHere++;
+
/* Wait for locker to lock mutex1 */
- assert(pthread_mutex_lock(&unlocker_start) == 0);
+ Sleep(500);
assert(pthread_mutex_unlock(&mutex1) == EPERM);
- assert(pthread_mutex_unlock(&unlocker_start) == 0);
-
+ wasHere++;
return 0;
}
@@ -47,16 +44,11 @@ main()
{
pthread_t t;
- assert(pthread_mutex_lock(&locker_start) == 0);
- assert(pthread_mutex_lock(&unlocker_start) == 0);
-
assert(pthread_create(&t, NULL, locker, NULL) == 0);
- assert(pthread_mutex_unlock(&locker_start) == 0);
- Sleep(0);
-
assert(pthread_create(&t, NULL, unlocker, NULL) == 0);
- assert(pthread_mutex_unlock(&unlocker_start) == 0);
- Sleep(0);
+ Sleep(2000);
+
+ assert(wasHere == 4);
return 0;
}