summaryrefslogtreecommitdiff
path: root/libpthread/tests/test-2.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2010-08-01 01:05:53 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-08-01 01:05:53 +0200
commit68567b88ee8f9e395e0c1f0a565affe8a1d4d68b (patch)
tree07d3b7b96832493cb3cc57a26e88157e354cf899 /libpthread/tests/test-2.c
parentfa0f7d1afb65bf077edfcc0f8977f95fca5656b9 (diff)
Move files to libpthread/ for inclusion along hurd
Diffstat (limited to 'libpthread/tests/test-2.c')
-rw-r--r--libpthread/tests/test-2.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libpthread/tests/test-2.c b/libpthread/tests/test-2.c
new file mode 100644
index 00000000..701462e8
--- /dev/null
+++ b/libpthread/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;
+}