bkeey的ChinaUnix博客
bkeey
全部博文(108)
ARM Linux(0)
ARM硬件(1)
深入理解Linux内(24)
Linux内核设计与(20)
APUE(0)
串口(4)
线程(1)
线程(3)
C++自学(15)
2015年(20)
2014年(88)
smile124
Bsolar
tanruiqi
yehowah_
:README
Hughie_S
琛宝fly
eddiegin
link8001
分类: C/C++
2014-04-04 12:56:04
原文地址:线程属性(线程分离) 作者:luozhiyong131
#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; }
上一篇:select,poll,epoll用法
下一篇:C++STL学习经典
登录 注册