所以程序就是这样工作的。有一个生产者和4个消费者。生产者生成6个随机数并通过消息队列将它们发送给4个消费者。每个消费者接收它们,并且在终止之前立即 ,应该通过另一个队列发送mayproduce = 0的一条消息; mayproduce是一个整数。消息队列不接受0作为参数
有问题的功能是:
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
我使用的功能像这样送mayproduce
msgsnd(qid,&mayproduce,sizeof(int),0)
当我编译它说: “无效参数”。
如果我改变mayproduce为其他号码,mayproduce = 2,程序工作正常。
有谁知道它不接受0作为参数的原因吗?
的代码示例:
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 == 0'不像“将'mayproduce'设置为另一个数字”。这是将'mayproduce'设置为0或1的比较。由于缺乏MCVE而投票结束。 –
是的@WeatherVane这是我的错误。我的意思是mayproduce = 0 – Ackerman