0
votes

I created a class "semaphore" with a method "reader" this way:

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);
}

In my main.cpp, I created these auxiliary variables, and instanced my class as follows:

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);

With this I get the following error:

void value not ignored as it ought to be

1
in which line exactly do you get the error?Mike van Dyke

1 Answers

2
votes

Your method "reader" returns void.
You use that invalid return value as a parameter to "pthread_creation". Casting void to pointer-to-void (which you seem to try) is not changing anything, not to say it is futile.

You cannot make a value from what a method returns, if it returns void.
That is what the error/warning is telling you.