summaryrefslogtreecommitdiff
path: root/tests/test-2.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-2.c')
-rw-r--r--tests/test-2.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test-2.c b/tests/test-2.c
new file mode 100644
index 00000000..701462e8
--- /dev/null
+++ b/tests/test-2.c
@@ -0,0 +1,39 @@
+/* Test detachability. */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <unistd.h>
+
+void *
+thread (void *arg)
+{
+ while (1)
+ sched_yield ();
+}
+
+int
+main (int argc, char **argv)
+{
+ int err;
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_create (&tid, 0, thread, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_detach (tid);
+ if (err)
+ error (1, err, "pthread_detach");
+
+ err = pthread_detach (tid);
+ assert (err == EINVAL);
+
+ err = pthread_join (tid, &ret);
+ assert (err == EINVAL);
+
+ return 0;
+}