7 /* function prototypes */
8 void *threadfun(void *arg
);
11 pthread_t tid
[NUM_THREADS
];
12 int i
, cnt
[NUM_THREADS
];
14 for (i
=0; i
<NUM_THREADS
; i
++) {
16 printf("Creating thread: %d\n", i
);
17 if (pthread_create(&tid
[i
], NULL
, threadfun
, (void *)&cnt
[i
])) {
18 fprintf(stderr
, "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 fprintf(stderr
, "pthread_join() error\n");
33 void *threadfun(void *arg
) {
34 printf("Hello! I am thread: %d\n", *(int *) arg
);