c语言带返回值的线程,ARTS-S C语言主线程获取子线程返回值

#include

#include

#include

typedef struct {

int stu_num;

char* stu_name;

}Student;

void *thr_fn1(void *arg) {

Student* student = (Student*)malloc(sizeof(Student));

student->stu_num = 1;

student->stu_name = "name1";

return((void *)student);

}

void *thr_fn2(void *arg) {printf("thread 2 exiting\n");

Student* student = (Student*)malloc(sizeof(Student));

student->stu_num = 2;

student->stu_name = "name2";

return((void *)student);

}

int main(void) {

int err;

pthread_t tid1, tid2;

void *tret;

err = pthread_create(&tid1, NULL, thr_fn1, NULL);

if (err != 0)

printf("can’t create thread 1:%d", err);

err = pthread_create(&t

你可能感兴趣的:(c语言带返回值的线程)