我以这种方式用方法“ reader”创建了一个“ semaphore”类:
void semaforo::reader(sem_t x, sem_t y,sem_t z,sem_t rsem,sem_t wsem){
cout<<"----------------"<<endl;
cout<<"Leitor esta Lendo"<<endl;
sem_wait(&z);
sem_wait(&rsem);
sem_wait(&x);
int aux = readcountM(0);
if(aux ==1){
sem_wait(&wsem);
}
sem_post(&x);
sem_post(&rsem);
sem_post(&z);
prints(1);
sem_wait(&x);
aux = readcountN(aux);
if(aux == 0){
sem_post(&wsem);
}
sem_post(&x);
}
在main.cpp中,我创建了这些辅助变量,并按如下方式实例化了我的类:
sem_t x,y,z,rsem,wsem;
pthread_t read[3],write[2];
thread *teste2 = new thread();
// the following line triggers the error
teste2->pthread_creation(&read[0],NULL,(void *)teste->reader(x, y, z, rsem, wsem),NULL);
有了这个我得到以下错误:
无效值不应该被忽略
最佳答案
您的方法“阅读器”返回void。
您可以使用该无效的返回值作为“ pthread_creation”的参数。将void转换为void指针(您似乎尝试过)并没有改变任何东西,并不是说它是徒劳的。
如果方法返回空值,则无法从该方法返回的值中获取值。
这就是错误/警告告诉您的内容。
关于c++ - “无效值不应该被忽略”-有什么问题吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47731042/