2 gcc pthread_join.c -o pthread_join -lpthread -Wall -W -Wextra -ansi -pedantic */
10 /* function prototypes */
11 void *threadfun(void *arg
);
12 void diep(const char *s
);
17 int cnt
[NUM_THREADS
], i
;
19 for (i
= 0; i
< NUM_THREADS
; i
++) {
21 printf("Creating thread: %d\n", i
);
23 if (pthread_create(&tid
, NULL
, threadfun
, (void *)&cnt
[i
]))
24 diep("pthread_create");
26 if (pthread_join(tid
, NULL
))
27 diep("pthread_join()");
33 void *threadfun(void *arg
)
35 printf("Hello! I am thread: %d\n", *(int *) arg
);
39 void diep(const char *s
)