3 * gcc pthread_create.c -o pthread_create -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
);
18 pthread_t tid
[NUM_THREADS
];
19 int cnt
[NUM_THREADS
], i
;
21 for (i
= 0; i
< NUM_THREADS
; i
++) {
23 printf("Creating thread: %d\n", i
);
24 if (pthread_create(&tid
[i
], NULL
, threadfun
, (void *)&cnt
[i
]))
25 diep("pthread_create() error\n");
28 /* Make sure all threads are done */
29 for (i
= 0; i
< NUM_THREADS
; i
++)
30 if (pthread_join(tid
[i
], NULL
))
36 void *threadfun(void *arg
)
38 printf("Hello! I am thread: %d\n", *(int *) arg
);
42 void diep(const char *s
)