about summary refs log tree commit diff
path: root/nptl/tst-mutex3.c
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/tst-mutex3.c')
-rw-r--r--nptl/tst-mutex3.c95
1 files changed, 92 insertions, 3 deletions
diff --git a/nptl/tst-mutex3.c b/nptl/tst-mutex3.c
index c45637b5cf..8e57924ba6 100644
--- a/nptl/tst-mutex3.c
+++ b/nptl/tst-mutex3.c
@@ -24,12 +24,25 @@
 
 
 static pthread_mutex_t m;
+static pthread_barrier_t b;
 
 
 static void *
 tf (void *arg)
 {
-  int e = pthread_mutex_trylock (&m);
+  int e = pthread_mutex_unlock (&m);
+  if (e == 0)
+    {
+      puts ("1st mutex_unlock in child succeeded");
+      exit (1);
+    }
+  if (e != EPERM)
+    {
+      puts ("1st mutex_unlock in child didn't return EPERM");
+      exit (1);
+    }
+
+  e = pthread_mutex_trylock (&m);
   if (e == 0)
     {
       puts ("mutex_trylock in second thread succeeded");
@@ -41,6 +54,44 @@ tf (void *arg)
       exit (1);
     }
 
+  e = pthread_barrier_wait (&b);
+  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      puts ("barrier_wait failed");
+      exit (1);
+    }
+
+  e = pthread_barrier_wait (&b);
+  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      puts ("barrier_wait failed");
+      exit (1);
+    }
+
+  e = pthread_mutex_unlock (&m);
+  if (e == 0)
+    {
+      puts ("2nd mutex_unlock in child succeeded");
+      exit (1);
+    }
+  if (e != EPERM)
+    {
+      puts ("2nd mutex_unlock in child didn't return EPERM");
+      exit (1);
+    }
+
+  if (pthread_mutex_trylock (&m) != 0)
+    {
+      puts ("2nd mutex_trylock in second thread failed");
+      exit (1);
+    }
+
+  if (pthread_mutex_unlock (&m) != 0)
+    {
+      puts ("3rd mutex_unlock in second thread failed");
+      exit (1);
+    }
+
   return NULL;
 }
 
@@ -68,6 +119,12 @@ do_test (void)
       return 1;
     }
 
+  if (pthread_barrier_init (&b, NULL, 2) != 0)
+    {
+      puts ("barrier_init failed");
+      return 1;
+    }
+
   if (pthread_mutex_lock (&m) != 0)
     {
       puts ("mutex_lock failed");
@@ -105,9 +162,10 @@ do_test (void)
       return 1;
     }
 
-  if (pthread_join (th, NULL) != 0)
+  int e = pthread_barrier_wait (&b);
+  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("join failed");
+      puts ("barrier_wait failed");
       return 1;
     }
 
@@ -117,6 +175,37 @@ do_test (void)
       return 1;
     }
 
+  e = pthread_mutex_unlock (&m);
+  if (e == 0)
+    {
+      puts ("4th mutex_unlock succeeded");
+      return 1;
+    }
+  if (e != EPERM)
+    {
+      puts ("4th mutex_unlock didn't return EPERM");
+      return 1;
+    }
+
+  e = pthread_barrier_wait (&b);
+  if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      puts ("barrier_wait failed");
+      return 1;
+    }
+
+  if (pthread_join (th, NULL) != 0)
+    {
+      puts ("join failed");
+      return 1;
+    }
+
+  if (pthread_barrier_destroy (&b) != 0)
+    {
+      puts ("barrier_destroy failed");
+      return 1;
+    }
+
   if (pthread_mutex_destroy (&m) != 0)
     {
       puts ("mutex_destroy failed");