2

我正在使用 System V 消息队列,它没有“定时接收”功能,如 POSIX MQ。但现在我需要它(这个定时接收功能)。

有人可能会问:“那你为什么不使用 POSIX 而不是 Sys V?”。因为在我的基准测试中,SysV MQ 比 POSIX MQ 快 +- 20%。

现在的问题。如何为 Sys V MQ 伪造“定时接收”?

我写了一段代码,它在循环中msgrcv使用. 我认为它很丑,所以我需要想法来写一个漂亮的=]IPC_NOWAITusleep

4

2 回答 2

0

This article shows the same thing you noticed, that you need to loop on it: http://linuxgazette.net/issue92/hawk.html

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. :)

于 2012-09-02T23:46:00.633 回答
0

您可以编写一个小代码,首先派生一个休眠 X 时间的子进程。唤醒后,它向父亲发送一个信号(如 SIGUSR1),中断父亲并取消 msgrcv。然后子进程死亡。但是您必须记住,您需要为该信号指定一个处理程序,因为默认的只是退出进程。

于 2012-01-04T19:23:36.407 回答