comparison src/pthreads-test.c @ 982:4d2e6c7c2cc2

test program for package pthreads (by Martin Lambers)
author Volker Grabsch <vog@notjusthosting.com>
date Sun, 16 May 2010 18:06:17 +0200
parents
children e55bb62b2970
comparison
equal deleted inserted replaced
981:26d50f1e4b29 982:4d2e6c7c2cc2
1 /* This file is part of mingw-cross-env. */
2 /* See doc/index.html for further information. */
3
4 #include <stdio.h>
5 #include <pthread.h>
6
7 #define N 10
8
9 void *thread_fn(void *p)
10 {
11 const int *arg = p;
12 fprintf(stderr, "Hello from thread %d\n", *arg);
13 return NULL;
14 }
15
16 int main(int argc, char *argv[])
17 {
18 pthread_t threads[N];
19 int args[N];
20 int i;
21
22 (void)argc;
23 (void)argv;
24
25 for (i = 0; i < N; i++) {
26 args[i] = i;
27 if (pthread_create(threads + i, NULL, thread_fn, args + i) != 0) {
28 return 1;
29 }
30 }
31
32 for (i = 0; i < N; i++) {
33 if (pthread_join(threads[i], NULL) != 0) {
34 return 2;
35 }
36 }
37
38 return 0;
39 }