pthread_join函数用于回收子线程,并且可以获取到子线程的退出状态;
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <pthread.h>
5
6
7
8 typedef struct
9 {
10 int a;
11 int b;
12 }exit_t;
13
14
15 void* tnf(void* arg)
16 {
17 exit_t* ret = (exit_t*)arg;
18 //ret = malloc(sizeof(exit_t));
19 ret->a = 100;
20 ret->b = 300;
21 pthread_exit((void*)ret);
22 }
23
24 int main()
25 {
26 pthread_t tid;
27 //exit_t** ret;
28 exit_t* ret =(exit_t*) malloc(sizeof(exit_t));
29 pthread_create(&tid,NULL,tnf,(void*)ret);
30 pthread_join(tid,(void**)&ret);
31 printf("a= %d,b= %d\n",ret->a,ret->b);
32 free(ret);
33 return 0;
34 }