EmbLogic's Blog

2 threads made

#include<stdio.h>
2 #include<stdlib.h>
3 #include<pthread.h>
4
5 void* mine_thread(void *arg);
6 void* mine_thread1(void *arg);
7
8 int main()
9 {
10         int ret,set;
11         int z=5,y=6;
12         void * result=malloc(5);
13         void * result1=malloc(5);
14         pthread_t a,b;
15
16         ret=pthread_create(&a,NULL,mine_thread,(void*)&z);//////creating thread
17         pthread_join(a,&result);////wait for the thread specified by thread to terminate
18
19         set=pthread_create(&b,NULL,mine_thread1,(void*)&y);
20         pthread_join(b,&result1);
21
22         sleep(5);
23         printf(“result=%s\n”,result);
24         printf(“result1=%s\n”,result1);
25 }
26
27 void* mine_thread(void *arg)///function of thread
28 {
29                 int a1;
30                 a1=*(int*)arg;
31                 printf(“value of a1 =%d\n”,a1);
32                 pthread_exit(“bye”);
33 }
34
1,8
result will be:-

a1=5

b1=6

result=bye

result1=take care

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>