home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / GianuzziV / SO1 / termina.c < prev    next >
C/C++ Source or Header  |  2001-11-11  |  759b  |  34 lines

  1. /* Processo che genera 2 thread, ciascuno dei quali
  2.    scrive 10 volte Hello o Ciao.
  3.    Da compilare come:
  4.    gcc -D_REENTRANT Es_termina.c -lpthread */
  5.  
  6. #include <pthread.h>
  7. #include <stdio.h>
  8.  
  9. void *Thread (void *string)
  10. {
  11.     int   i;
  12.     for (i=0; i<10; i++)
  13.           printf ("%s\n", (char *)string);
  14.           pthread_exit(NULL);
  15. }
  16.  
  17. int main ()
  18. {
  19.    char  *e_str = "Hello",  *f_str = "Ciao";
  20.    pthread_t    e_th,  f_th;
  21.    int  rc, status;
  22.  
  23.    rc = pthread_create(&e_th, NULL, Thread, (void *)e_str);
  24.    if (rc)    exit (-1);
  25.    rc = pthread_create(&f_th, NULL, Thread, (void *)f_str);
  26.    if (rc)    exit (-1);
  27.    pthread_join(f_th, (void *)&status);
  28.    pthread_join(e_th, (void *)&status);
  29.    printf("termina il main \n");
  30.    pthread_exit (NULL);
  31. }
  32.  
  33.  
  34.