Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<sys/types.h>
- #include<unistd.h>
- #include<stdio.h>
- #include<pthread.h>
- pthread_t tid;
- int status,a=0,b=0,c=0;
- void* funz1(void* arg)
- {
- tid=pthread_self();
- int pid=getpid();
- printf("[Thread1]TID:%u \n",(unsigned int) tid);
- printf("DIN \n");
- pthread_exit((void*)status);}
- void* funz2(void* arg)
- {
- tid=pthread_self();
- int pid=getpid();
- printf("[Thread2]TID:%u \n",(unsigned int) tid);
- printf("DON \n");
- pthread_exit((void*)status);}
- void* funz3(void* arg)
- {
- tid=pthread_self();
- int pid=getpid();
- printf("[Thread2]TID:%u \n",(unsigned int) tid);
- printf("DAN \n");
- pthread_exit((void*)status);}
- int main() {
- pthread_t t1,t2,t3;
- int pid=getpid();
- printf("[Main]PID:%d \n",pid);
- int thr1=pthread_create(&t1, NULL, funz1, NULL);
- if(thr1!=0)printf("Errore");
- int thr2=pthread_create(&t2, NULL, funz2, NULL);
- if(thr2!=0)printf("Errore");
- int thr3=pthread_create(&t3, NULL, funz3, NULL);
- if(thr2!=0)printf("Errore");
- pthread_join(t1, (void*)status);
- if(status==0) printf("Thread terminato \n");
- printf("[Main]TID:%u \n", (unsigned int)tid);
- pthread_join(t2, (void*)status);
- if(status==0) printf("Thread terminato \n");
- printf("[Main]TID:%u \n", (unsigned int)tid);
- pthread_join(t3, (void*)status);
- if(status==0) printf("Thread terminato \n");
- printf("[Main]TID:%u \n", (unsigned int)tid);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement