So the program works like this. There is a producer, and 4 consumers. The producer generates 6 random numbers and sends them through message queues into the 4 consumers. Each consumer receives them and, immediately before terminating, should send through another queue one message with mayproduce=0; mayproduce is an integer.
The function in question is:
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
I use the function like this to send mayproduce
msgsnd(qid,&mayproduce,sizeof(int),0)
when I compile it says "Invalid argument".
If I change mayproduce to other number, for mayproduce=2, the program works fine.
Does anyone know the reason it doesn't accept 0 as an argument?
A sample of the code:
mayproduce=2; // if I put 0 here it doesn't work
if(msgsnd(msq2,&mayproduce,tamanho,0)<0) {
perror("\nConsumidor:Erro ao enviar a mensagem: ");
exit(1);
}
mayproduce==0is not like "settingmayproduceto another number". It is a comparison which setsmayproduceto 0 or 1. Voting to close for lack of MCVE.