7 /* function prototypes */
8 void *threadfun(void *arg
);
9 void diep(const char *s
);
13 pthread_t tid
[NUM_THREADS
];
14 int cnt
[NUM_THREADS
], i
;
16 for (i
= 0; i
< NUM_THREADS
; i
++) {
18 printf("Creating thread: %d\n", i
);
19 if (pthread_create(&tid
[i
], NULL
, threadfun
, (void *)&cnt
[i
]))
20 diep("pthread_create() error\n");
23 /* make sure all threads are done */
24 for (i
= 0; i
< NUM_THREADS
; i
++)
25 if (pthread_join(tid
[i
], NULL
))
26 perror("pthread_join");
31 void *threadfun(void *arg
)
33 printf("Hello! I am thread: %d\n", *(int *) arg
);
37 void diep(const char *s
)