Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- pthread_t tid[3];
- // method for the threads to run
- void * test(){
- pthread_t id = pthread_self();
- int threadNum = 0;
- if(pthread_equal(id,tid[0]))
- threadNum = 1;
- else if(pthread_equal(id, tid[1]))
- threadNum = 2;
- else if (pthread_equal(id, tid[2]))
- threadNum = 3;
- int i;
- for(i = 1; i < 11; i ++)
- printf("%d: %d\n",threadNum,i);
- }
- // main method creates threads
- int main(void){
- int i = 2;
- int err;
- while(i>=0){
- if(pthread_create(&(tid[i]),NULL,&test,NULL) != 0) printf("Error in creating thread");
- i--;
- }
- //sleep(1);
- wait();
- printf("Application is finished\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement