#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void mythread()
{
printf("thread is pthread:n");
sleep(1);
printf("thread is exitingn");
int thread_finished = 1;
pthread_exit(NULL);
}
int main()
{
pthread_t id;
pthread_attr_t thread_attr;
int ret,thread_finished;
ret = pthread_attr_init(&thread_attr);
if(ret!=0)
{
printf("pthread_attr_init errorn");
exit(1);
}
ret = pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
if(ret!=0)
{
printf("pthread_attr_setdetachstate errorn");
exit(1);
}
ret = pthread_create(&id,&thread_attr,(void *)mythread,NULL);
if(ret!=0)
{
printf("create pthread errorn");
exit(1);
}
while(!thread_finished)
{
printf("waitint for thread finished..n");
sleep(1);
}
printf("Donen");
return 0;
}
|