2 gcc pthread_create.c -o pthread_create -lpthread -Wall -W -Wextra -ansi -pedantic */
10 /* function prototypes */
11 void *threadfun(void *arg
);
12 void diep(const char *s
);
16 pthread_t tid
[NUM_THREADS
];
17 int cnt
[NUM_THREADS
], i
;
19 for (i
= 0; i
< NUM_THREADS
; i
++) {
21 printf("Creating thread: %d\n", i
);
22 if (pthread_create(&tid
[i
], NULL
, threadfun
, (void *)&cnt
[i
]))
23 diep("pthread_create() error\n");
26 /* make sure all threads are done */
27 for (i
= 0; i
< NUM_THREADS
; i
++)
28 if (pthread_join(tid
[i
], NULL
))
34 void *threadfun(void *arg
)
36 printf("Hello! I am thread: %d\n", *(int *) arg
);
40 void diep(const char *s
)