6 void *thread_function(void *arg); /* Pointer to function executed by each thread */
14 pthread_t threads[NUM];
19 for (i = 0; i < NUM; i++)
22 res = pthread_create(&threads[i], NULL, thread_function, (void *)&args[i]);
25 for (i = 0; i < NUM; i++)
26 res = pthread_join(threads[i], &thread_result);
36 void *thread_function(void *arg) {
37 int my_number = *(int *)arg;
40 printf ("Print 1, thread %d\n", my_number);
45 printf ("Print 2, thread %d\n", my_number);
47 printf ("Print 3, thread %d\n", my_number);
49 printf ("Print 4, thread %d\n", my_number);
51 printf ("Print 5, thread %d\n", my_number);
55 printf("Bye from %d\n", my_number);