summaryrefslogtreecommitdiff
path: root/tests/test-8.c
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2002-10-10 23:05:06 +0000
committerNeal H. Walfield <neal@gnu.org>2002-10-10 23:05:06 +0000
commit291996a60567617f17aeb5e96159290b1ba22340 (patch)
tree6ea49340f541fdfe5cdac36ba0949b8718fd1e0b /tests/test-8.c
Import libpthread.
Diffstat (limited to 'tests/test-8.c')
-rw-r--r--tests/test-8.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test-8.c b/tests/test-8.c
new file mode 100644
index 00000000..85a7f8f6
--- /dev/null
+++ b/tests/test-8.c
@@ -0,0 +1,60 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+pthread_once_t inc_var_once = PTHREAD_ONCE_INIT;
+int var;
+
+void
+inc_var (void)
+{
+ var ++;
+}
+
+void *
+thr (void *arg)
+{
+ int i;
+
+ for (i = 0; i < 500; i ++)
+ pthread_once (&inc_var_once, inc_var);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ err = pthread_create (&tid[i], 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ assert (thr (0) == 0);
+
+ for (i = 0; i < THREADS; i ++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ assert (var == 1);
+
+ return 0;
+}