Advertisement
Guest User

esercizio campane

a guest
Jan 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. #include<sys/types.h>
  2. #include<unistd.h>
  3. #include<stdio.h>
  4. #include<pthread.h>
  5.  
  6. pthread_t tid;
  7. int status,a=0,b=0,c=0;
  8.  
  9. void* funz1(void* arg)
  10. {
  11. tid=pthread_self();
  12. int pid=getpid();
  13. printf("[Thread1]TID:%u \n",(unsigned int) tid);
  14. printf("DIN \n");
  15. pthread_exit((void*)status);}
  16.  
  17. void* funz2(void* arg)
  18. {
  19. tid=pthread_self();
  20. int pid=getpid();
  21. printf("[Thread2]TID:%u \n",(unsigned int) tid);
  22. printf("DON \n");
  23. pthread_exit((void*)status);}
  24.  
  25.  
  26. void* funz3(void* arg)
  27. {
  28. tid=pthread_self();
  29. int pid=getpid();
  30. printf("[Thread2]TID:%u \n",(unsigned int) tid);
  31. printf("DAN \n");
  32. pthread_exit((void*)status);}
  33.  
  34.  
  35.  
  36.  
  37. int main() {
  38.  
  39. pthread_t t1,t2,t3;
  40. int pid=getpid();
  41. printf("[Main]PID:%d \n",pid);
  42. int thr1=pthread_create(&t1, NULL, funz1, NULL);
  43. if(thr1!=0)printf("Errore");
  44.  
  45. int thr2=pthread_create(&t2, NULL, funz2, NULL);
  46. if(thr2!=0)printf("Errore");
  47.  
  48. int thr3=pthread_create(&t3, NULL, funz3, NULL);
  49. if(thr2!=0)printf("Errore");
  50.  
  51.  
  52. pthread_join(t1, (void*)status);
  53. if(status==0) printf("Thread terminato \n");
  54. printf("[Main]TID:%u \n", (unsigned int)tid);
  55.  
  56. pthread_join(t2, (void*)status);
  57. if(status==0) printf("Thread terminato \n");
  58. printf("[Main]TID:%u \n", (unsigned int)tid);
  59.  
  60. pthread_join(t3, (void*)status);
  61. if(status==0) printf("Thread terminato \n");
  62. printf("[Main]TID:%u \n", (unsigned int)tid);
  63.  
  64.  
  65.     return 0;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement