Fix matrix_read() in respect to the new error handling scheme we follow
[eleutheria.git] / pthreads / pthread_join.c
blob6cae86985ad6b05e50355c83c9c2da5929b60a05
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <pthread.h>
5 #define NUM_THREADS 20
7 /* function prototypes */
8 void *threadfun(void *arg);
9 void diep(const char *s);
11 int main(void)
13 pthread_t tid;
14 int cnt[NUM_THREADS], i;
16 for (i = 0; i < NUM_THREADS; i++) {
17 cnt[i] = i;
18 printf("Creating thread: %d\n", i);
20 if (pthread_create(&tid, NULL, threadfun, (void *)&cnt[i]))
21 diep("pthread_create");
23 if (pthread_join(tid, NULL))
24 diep("pthread_join()");
27 return EXIT_SUCCESS;
30 void *threadfun(void *arg)
32 printf("Hello! I am thread: %d\n", *(int *) arg);
33 pthread_exit(NULL);
36 void diep(const char *s)
38 perror(s);
39 exit(EXIT_FAILURE);