64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <pthread.h>
#include <string>
#define MAX_NUM_PTHREAD 5
using namespace std;
void* Set_Infor1(void* argc);
struct student
{
string name;
int num;
int age;
};
int main()
{
pthread_t pids[MAX_NUM_PTHREAD];
pthread_attr_t attr;
void* infor;
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&pids[0], &attr, Set_Infor1, NULL);
pthread_attr_destroy(&attr);
pthread_join(pids[0], &infor);
cout << "name: "<<((student*)infor)->name << " num: "<<((student*)infor)->num << " age: "<<((student*)infor)->age <<endl;
}
void* Set_Infor1(void* argc)
{
cout<<"I am thread 1"<<endl;
struct student student1;
student1.name = "Zeng";
student1.num = 111;
student1.age = 22;
pthread_exit((void*)&student1);
}
不要返回局部变量(student1)的地址
不要返回局部变量(student1)的地址