当前位置: 技术问答>linux和unix
linux 创建线程中的问题
来源: 互联网 发布时间:2017-02-06
本文导语: #include #include #include #include struct chuan { int h; char a; }; void *myThread1(struct chuan *q1) { printf("This is the 1st pthread,created by zieckey.n"); printf("The struct is %dn",q1.h); ...
#include
#include
#include
#include
struct chuan
{
int h;
char a;
};
void *myThread1(struct chuan *q1)
{
printf("This is the 1st pthread,created by zieckey.n");
printf("The struct is %dn",q1.h);
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
int main()
{
int i=0, ret=0;
pthread_t id1;
struct chuan qq={1,"d"};
ret = pthread_create(&id1, NULL, (void*)myThread1,&qq );
if (ret)
{
printf("Create pthread error!n");
return 1;
}
pthread_join(id1, NULL);
return 0;
}
提示出错:request for member ‘h’ in something not a structure or union
#include
#include
#include
struct chuan
{
int h;
char a;
};
void *myThread1(struct chuan *q1)
{
printf("This is the 1st pthread,created by zieckey.n");
printf("The struct is %dn",q1.h);
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
int main()
{
int i=0, ret=0;
pthread_t id1;
struct chuan qq={1,"d"};
ret = pthread_create(&id1, NULL, (void*)myThread1,&qq );
if (ret)
{
printf("Create pthread error!n");
return 1;
}
pthread_join(id1, NULL);
return 0;
}
提示出错:request for member ‘h’ in something not a structure or union
|
void *myThread1(void *ThreadData)
{
struct chuan *q1 = (struct chuan *)ThreadData
printf("This is the 1st pthread,created by zieckey.n");
printf("The struct is %dn",q1->h);
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
{
struct chuan *q1 = (struct chuan *)ThreadData
printf("This is the 1st pthread,created by zieckey.n");
printf("The struct is %dn",q1->h);
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
|
thank you very much
|
q1.h ---> q1->h