Linux编程:线程终止、线程挂起(类似进程的wait)函数使用
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
typedef struct{
int a;
int b;
}exit_t;
void *tfn(void *arg)
{
exit_t *ret;
ret=malloc(sizeof(exit_t));
ret->a=100;
ret->b=200;
pthread_exit((void *)ret);//线程终止//参数可以为NULL
return NULL;//线程返回
}
int main(void)
{
pthread_t tid;
exit_t * retval;
pthread_create(&tid,NULL,tfn,NULL);
//调用pthread_join获取线程退出状态
pthread_join(tid,(void**)&retval);
printf("a=%d,b=%d\n",retval->a,retval->b);
return 0;
}

被折叠的 条评论
为什么被折叠?



