summaryrefslogtreecommitdiff
path: root/test/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'test/nptl')
-rw-r--r--test/nptl/Makefile.in2
-rw-r--r--test/nptl/tst-cond-deadlock.c51
2 files changed, 52 insertions, 1 deletions
diff --git a/test/nptl/Makefile.in b/test/nptl/Makefile.in
index ac2aa8b1e..f8dd1ca90 100644
--- a/test/nptl/Makefile.in
+++ b/test/nptl/Makefile.in
@@ -31,7 +31,7 @@ TESTS := tst-align tst-align2 tst-atfork1 tst-attr1 tst-attr2 tst-attr3 \
tst-signal5 tst-signal6 tst-spin1 tst-spin2 tst-spin3 \
tst-stack1 tst-stack2 tst-stdio1 tst-stdio2 tst-sysconf \
tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tsd1 tst-tsd2 \
- tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 \
+ tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 tst-cond-deadlock \
tst-align3 tst-cancel4 tst-cancel5 tst-cancel18 tst-cancel23 \
tst-cancel25 tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx6 \
tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 tst-cancelx11 \
diff --git a/test/nptl/tst-cond-deadlock.c b/test/nptl/tst-cond-deadlock.c
new file mode 100644
index 000000000..dd978fb3d
--- /dev/null
+++ b/test/nptl/tst-cond-deadlock.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Martin Willi <martin@strongswan.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <pthread.h>
+
+static pthread_mutex_t m;
+static pthread_cond_t c;
+static pthread_t t;
+static volatile int ready;
+
+static void cancelcb(void *arg)
+{
+ pthread_mutex_unlock(&m);
+}
+
+static void* threadcb(void *arg)
+{
+ pthread_mutex_lock(&m);
+ pthread_cleanup_push(cancelcb, NULL);
+
+ ready = 1;
+ while (1)
+ pthread_cond_wait(&c, &m);
+ pthread_cleanup_pop(1);
+}
+
+static int
+do_test (void)
+{
+ pthread_mutex_init(&m, NULL);
+ pthread_cond_init(&c, NULL);
+
+ pthread_create(&t, NULL, threadcb, NULL);
+
+ while (!ready);
+
+ pthread_cancel(t);
+ pthread_join(t, NULL);
+
+ pthread_cond_signal(&c);
+ pthread_cond_destroy(&c);
+ pthread_mutex_destroy(&m);
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 100
+#include "../test-skeleton.c"