我试图将结构中的一些变量放入单独线程中的另一个变量中,但我似乎无法做到这一点。我有一个像这样的结构
typedef struct arguments {
char thisStart[10];
char thisWalkno[10];
char thisMatsize[10];
char thisShmkey[10];
int *pint;
}arguments;
然后我有了我的 main,在一些初始变量声明之后,我开始将变量放入我的结构中
main ( int argc, char argv[]) {
arguments tid_arg;
pthread_t tid;
.
.
.
.
sprintf(tid_arg.thisWalkno, "%d", (m + 1));
sprintf(tid_arg.thisStart, "%d", start);
sprintf(tid_arg.thisMatsize, "%d", matsize);
sprintf(tid_arg.thisShmkey, "%d", shmkey);
pthread_attr_init(&attr);
/* create the thread */
if (pthread_create(&tid, &attr, tidchild, (void *)&tid_arg) != 0) {
printf("Could not execute child program\n");
exit(1);
}
.
.
.
}
最后是我的 tid 子函数
void *tidchild(void *tid_arg) {
struct arguments *args = tid_arg;
int walkno, start, shmid, matsize;
walkno = atoi(args.thisWalkno);
pthread_exit(0);
}
当我到达 walkno = atoi(args.thisWalkno)
时,这就是我的错误出现的地方,我似乎无法从结构访问 thisWalkno 。有人可以帮助我吗?
此外,我忘了提及,当我输入 args->thisWalkno
时,我收到“取消引用指向不完整类型的指针”错误。
最佳答案
args
是指向结构体的指针,使用 args->thisWalkno
并且您应该#include
struct
> 定义在任何需要使用的地方。
关于c - 请求非结构或 union 中的成员 ‘thisWalkno’。 (P线程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29335956/