我用方法"读取器"创建了一个类"信号":
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值不忽略,因为它应该为
您的方法"读取器"返回void。
您将无效的返回值用作" pthread_creation"的参数。将空隙施放到指针到空中(您似乎尝试过)没有改变任何东西,并不是说它是徒劳的。
如果方法返回void。
这就是错误/警告告诉您的。