所以程序就是這樣工作的。有一個生產者和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