3 * gcc pthread_join.c -o pthread_join -lpthread -Wall -W -Wextra -ansi -pedantic
10 #define NUM_THREADS 20
12 /* function prototypes */
13 void *threadfun(void *arg
);
14 void diep(const char *s
);
19 int cnt
[NUM_THREADS
], i
;
21 for (i
= 0; i
< NUM_THREADS
; i
++) {
23 printf("Creating thread: %d\n", i
);
25 if (pthread_create(&tid
, NULL
, threadfun
, (void *)&cnt
[i
]))
26 diep("pthread_create");
28 if (pthread_join(tid
, NULL
))
29 diep("pthread_join()");
35 void *threadfun(void *arg
)
37 printf("Hello! I am thread: %d\n", *(int *) arg
);
41 void diep(const char *s
)