#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<string.h>
void *func1(void *arg);
char m[]="hi how r u";
int main()
{
int r,x;
void *p;
pthread_t a;
r=pthread_create(&a,NULL,func1,(void *)m);
if(r!=0)
{
perror("thread creation failed : ");
exit(EXIT_FAILURE);
}
else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");
}
else
sleep(3);
x=pthread_cancel(a);
if(x==-1)
{
perror("thrAed cancel failed ");
}
else
{
printf("\n thread cancelled");
r=pthread_join(a,&p);
if(r!=0)
{
perror("thread joining failed :");
exit(EXIT_FAILURE);
}
printf("\n thread joined with value %s ", (char *)p);
printf("\n messafe is %s",m);
exit(EXIT_SUCCESS);
}
}
No comments:
Post a Comment