lchjczwlchjczw.blog.chinaunix.net
lchjczw
全部博文(1008)
sysfs(0)
procfs(6)
Java(0)
Linux C(1)
C++(0)
C语言(0)
wifi驱动开发(0)
视频驱动开发(0)
音频驱动开发(2)
网络设备驱动开发(1)
驱动调试(0)
驱动基础(4)
sd卡驱动开发(1)
总线驱动(9)
flash驱动开发(0)
USB驱动开发(1)
2012年(1008)
Lanny_li
zsy77
cynthia
Bsolar
浪花小雨
fengchar
yxl15098
wangfeng
CHLRX
728196
Katherin
分类:
2012-08-01 11:35:06
原文地址:线程属性(线程分离) 作者: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; }
上一篇:线程同步(互斥量)
下一篇:线程终止
登录 注册