From: muench Date: Mon, 17 Feb 2003 09:25:51 +0000 (+0000) Subject: join with pthread-d4 -- mm X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=063f0edbdaddf5dafb4e54e9e956b8889a60b6b1;p=daqdata.git join with pthread-d4 -- mm --- diff --git a/compat/examples/testpthread.c b/compat/examples/testpthread.c new file mode 100644 index 0000000..f391e27 --- /dev/null +++ b/compat/examples/testpthread.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +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); +}