]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
join with pthread-d4 -- mm
authormuench <muench>
Mon, 17 Feb 2003 09:25:51 +0000 (09:25 +0000)
committermuench <muench>
Mon, 17 Feb 2003 09:25:51 +0000 (09:25 +0000)
compat/examples/testpthread.c [new file with mode: 0644]

diff --git a/compat/examples/testpthread.c b/compat/examples/testpthread.c
new file mode 100644 (file)
index 0000000..f391e27
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <time.h>
+
+void *thrTest0(void *arg)
+{
+       struct timespec tS, *t = &tS;
+
+       t->tv_sec = rand() / (RAND_MAX / 3);
+       t->tv_nsec = 0;
+       nanosleep(t, NULL);
+
+       puts("thread 0");
+       return NULL;
+}
+
+void *thrTest1(void *arg)
+{
+       struct timespec tS, *t = &tS;
+
+       t->tv_sec = rand() / (RAND_MAX / 3);
+       t->tv_nsec = 0;
+       nanosleep(t, NULL);
+       puts("thread 1");
+       return NULL;
+}
+
+void *thrTest2(void *arg)
+{
+       struct timespec tS, *t = &tS;
+
+       t->tv_sec = rand() / (RAND_MAX / 3);
+       t->tv_nsec = 0;
+       nanosleep(t, NULL);
+       puts("thread 2");
+       return NULL;
+}
+
+int main(int argc, char *argv[]) {
+       pthread_t t0;
+       pthread_t t1;
+       pthread_t t2;
+       int i;
+
+       for (i = 0; i < 100; i++) {
+               pthread_create(&t0, NULL, thrTest0, NULL);
+               pthread_create(&t1, NULL, thrTest1, NULL);
+               pthread_create(&t2, NULL, thrTest2, NULL);
+
+               pthread_join(t0, NULL);
+               pthread_join(t1, NULL);
+               pthread_join(t2, NULL);
+       }
+
+       exit(0);
+}