Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include<time.h>
- #include<ctime>
- void *myThreadFun(void *vargp);
- void *my_date(void *thread);
- void *my_fun(void *type);
- // A normal C function that is executed as a thread
- // when its name is specified in pthread_create()
- void *myThreadFun(void *vargp)
- {
- printf("thread :%d\n",(int*)vargp);
- printf("Printing GeeksQuiz from Thread \n");
- // return NULL;
- }
- int main()
- {
- pthread_t tid,tid_2,tid_3;
- // printf("Before Thread\n");
- pthread_create(&tid, NULL, myThreadFun, (void*)1);
- pthread_create(&tid_2,NULL,my_fun,(void*)2);
- pthread_create(&tid_3,NULL,my_date,(void*)3);
- pthread_join(tid, NULL);
- //printf("After Thread\n");
- }
- void *my_fun(void *type)
- {
- printf("Thread:%d\n",(int*)type);
- printf("random number\n");
- time_t t1;
- srand((unsigned) time(&t1));
- int random = rand() % 10;
- printf("rand=%d\n",random);
- // return NULL;
- }
- void *my_date(void *thr)
- {
- printf("thread :%d\n",(int*)thr);
- time_t curr_time;
- curr_time = time(NULL);
- char *tm = ctime(&curr_time);
- printf("Today date is %s\n",tm);
- printf("\n\n\t\t\tCoding is Fun !\n\n\n");
- //111return NULL;
- }
Add Comment
Please, Sign In to add comment