summaryrefslogtreecommitdiff
path: root/tests/mutex4.c
diff options
context:
space:
mode:
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;
}