如何保持阻塞状态以阅读消息队列?

发布于 2025-01-23 06:29:34 字数 394 浏览 2 评论 0原文

消息队列发件人由多计数器启动。消息队列标志正在阻止。我不能使用循环从消息队列中读取消息,因为它需要太多资源。有什么方法可以让我的功能在消息队列中有消息后立即调用MSGRCV()读取消息。感谢您的建议和答案!我们在我们的程序中使用MSGGET 、MSGCTL 、MSGSND、MSGSND。

for(;;){
  msglen = msgrcv(serverId,&req, REQ_MSG_SIZE,0,0);
  if (msgLen ==-1){
    errMsg("msgrcv");
    break; 
  }
...
}

在这里,我用来连续调用MSGRCV函数以读取消息队列中的消息。CPU使用率将达到100%。这是我不使用循环的一种方式,当消息队列带有消息MSGRCV并阅读消息时。

The message queue sender is started by a multi-timer. The message queue flag is blocking. I can't use a loop to read messages from the message queue because it takes too much resources. Is there any way that my function can call the msgrcv() to read the message as soon as there is a message in the message queue.Thanks a lot for your suggestions and answers! we use msgget、msgctl、msgsnd、msgrcv in our programm.

for(;;){
  msglen = msgrcv(serverId,&req, REQ_MSG_SIZE,0,0);
  if (msgLen ==-1){
    errMsg("msgrcv");
    break; 
  }
...
}

Here I use for to continuously call the msgrcv function to read the messages in the message queue.The cpu usage will reach 100%. is here a way for me to not use a for loop, when the message queue has a message msgrcv will be called and read the message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文