1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *my_thread_process (void * arg)
{
int i;
for (i = 0 ; i < 5 ; i++) {
printf ("Thread %s: %d\n", (char*)arg, i);
sleep (1);
}
pthread_exit (0);
}
main (int ac, char **av)
{
pthread_t th1, th2;
void *ret;
if (pthread_create (&th1, NULL, my_thread_process, "1") < 0) {
fprintf (stderr, "pthread_create error for thread 1\n");
exit (1);
}
if (pthread_create (&th2, NULL, my_thread_process, "2") < 0) {
fprintf (stderr, "pthread_create error for thread 2\n");
exit (1);
}
(void)pthread_join (th1, &ret);
(void)pthread_join (th2, &ret);
} |
Partager