ccx_wz的ChinaUnix博客chencaixiong.blog.chinaunix.net
ccx_wz
全部博文(489)
2013年(7)
2012年(301)
2011年(181)
jiuniu11
liangsto
sh365
dyli2000
CU官方博
y3079214
smsong_c
rubik_ns
guoxiaor
wb123456
cynthia
浪花小雨
Bsolar
178919
tomcodin
UMK_eRai
linux_ss
分类:
2011-12-22 20:50:52
原文地址:线程属性(线程分离) 作者: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; }
上一篇:线程同步(互斥量)
下一篇:线程终止
登录 注册