所以我一直在犯错误
request for member ‘iArray’ in something not a structure or union
int place = q.iArray[q.in];//reorder
我有另一个功能,这个电话很完美,但出于某种原因,在我的消费者福利中它生产这个电话......
我的cdoe是:
typedef struct _struct_x
{
int iArray[MAX_COUNT];
int in;
int out;
} struct_x;
struct_x q;
void * consumer (void *t)
{
int tid = * (int *)t;
printf ("consumer started\n");
while (!done)
{
printf("IM IN THIS LOOP\n");
int q = rand() % 1000 + 1;
pthread_mutex_lock (&count_mutex);
usleep(q*1000);
if (count <= 0)
{
//its empty..
}
else{
int place = q.iArray[q.in];//reorder
q.in = (q.in+1)%MAX_COUNT;
int facto = 0;
printf("Consumer removed %d, computed %d != &d, queue size = %d\n",place,place,facto,count);
count--;
}
pthread_mutex_unlock (&count_mutex);
}
printf ("T2[%d] thread done.\n", tid);
pthread_exit (NULL);
}
我想我的主要问题是导致这种错误的原因
答案 0 :(得分:2)
您已将q重新定义为此行中的整数 -
int q = rand() % 1000 + 1;
这导致编译错误。