问题描述
Im使用System V消息队列,它不具有定时接收"功能,例如POSIX MQ.但是现在我需要它(该定时接收功能.).
Im using System V Message Queue, which does not have a "timed receive" function, like POSIX MQ.But now i need it (this timed receive func.).
一个人会问:那为什么不使用POSIX而不是Sys V?".因为在我的基准测试中,SysV MQ比POSIX MQ快20%.
One can ask: "so why dont you use POSIX instead of Sys V?". Because in my benchmarks SysV MQ was +- 20% faster than POSIX MQ.
现在是问题.如何为Sys V MQ伪造定时接收"?
Now the question.How to fake a "timed receive" for Sys V MQ?
我编写了一段代码,用usleep
循环对msgrcv
和IPC_NOWAIT
进行了测试.我认为它很丑陋,所以我需要创意写一个漂亮的=]
I wrote a piece of code that does it testing msgrcv
with IPC_NOWAIT
in a loop with usleep
.I think its ugly, so i need ideas to write a beautiful one =]
推荐答案
本文显示了您注意到的相同内容,需要对其进行循环: http://linuxgazette.net/issue92/hawk.html
This article shows the same thing you noticed, that you need to loop on it: http://linuxgazette.net/issue92/hawk.html
然后继续提出内核修改以解决此问题. YMMV,但我怀疑您将无法仅仅为了做到这一点而对您的内核进行黑客攻击. :)
Then it goes on to propose a kernel modification to work around this. YMMV, but I suspect you won't be in a position to hack your kernel just to do this. :)
这篇关于系统V消息队列-定时接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!