Chinaunix首页 | 论坛 | 博客
  • 博客访问: 268130
  • 博文数量: 113
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1044
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-15 16:09
文章分类

全部博文(113)

文章存档

2016年(5)

2015年(108)

我的朋友

分类: C/C++

2016-02-11 02:08:48

pthread_exit()
pthread_join()


#include
#include
#include
#include
struct stu{
int num;
char name[10];
};
void *fun(void *arg){
int i;
struct stu *s;
s=malloc(sizeof(struct stu));
s->num=100;
strcpy(s->name,"hello");
for(;;){
printf("pthread is running ...\n");

sleep(1);
if(i>10)
{pthread_exit((void *)s);
}
i++;
}
}
int main(){
pthread_t pid;
struct stu *s1;
int ret;
ret=pthread_create(&pid,NULL,fun,NULL);
pthread_join(pid,(void **)& s1);
printf("%d %s\n",s1->num,s1->name);
free(s1);
printf("pthread end...\n");
return 0;
}

阅读(2118) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~