about summary refs log tree commit diff
path: root/nptl/tst-robust9.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /nptl/tst-robust9.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.xz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip
2.5-18.1
Diffstat (limited to 'nptl/tst-robust9.c')
-rw-r--r--nptl/tst-robust9.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/nptl/tst-robust9.c b/nptl/tst-robust9.c
new file mode 100644
index 0000000000..1d6ba179be
--- /dev/null
+++ b/nptl/tst-robust9.c
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+static pthread_mutex_t m;
+
+static void *
+tf (void *data)
+{
+  int err = pthread_mutex_lock (&m);
+  if (err == EOWNERDEAD)
+    {
+      err = pthread_mutex_consistent_np (&m);
+      if (err)
+	{
+	  puts ("pthread_mutex_consistent_np");
+	  exit (1);
+	}
+    }
+  else if (err)
+    {
+      puts ("pthread_mutex_lock");
+      exit (1);
+    }
+  printf ("thread%ld got the lock.\n", (long int) data);
+  sleep (1);
+  /* exit without unlock */
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  int err, i;
+  pthread_t t[3];
+  pthread_mutexattr_t ma;
+
+  pthread_mutexattr_init (&ma);
+  err = pthread_mutexattr_setrobust_np (&ma, PTHREAD_MUTEX_ROBUST_NP);
+  if (err)
+    {
+      puts ("pthread_mutexattr_setrobust_np");
+      return 1;
+    }
+#ifdef ENABLE_PI
+  if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_INHERIT) != 0)
+    {
+      puts ("pthread_mutexattr_setprotocol failed");
+      return 1;
+    }
+#endif
+  err = pthread_mutex_init (&m, &ma);
+#ifdef ENABLE_PI
+  if (err == ENOTSUP)
+    {
+      puts ("PI robust mutexes not supported");
+      return 0;
+    }
+#endif
+  if (err)
+    {
+      puts ("pthread_mutex_init");
+      return 1;
+    }
+
+  for (i = 0; i < sizeof (t) / sizeof (t[0]); i++)
+    {
+      err = pthread_create (&t[i], NULL, tf, (void *) (long int) i);
+      if (err)
+	{
+	  puts ("pthread_create");
+	  return 1;
+	}
+    }
+
+  for (i = 0; i < sizeof (t) / sizeof (t[0]); i++)
+    {
+      err = pthread_join (t[i], NULL);
+      if (err)
+	{
+	  puts ("pthread_join");
+	  return 1;
+	}
+    }
+  return 0;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"