如何知道 boost::interprocess::message_queue 已从系统中删除?

How to get know that boost::interprocess::message_queue was removed from system?

我基于 boost::interprocess::message_queue 创建了 Sender/Receiver 包装器,用于从一个进程发送消息并在另一个进程接收消息,您可以在此处查看源代码:https://gist.github.com/onto/c322bb0a33433b775966

有一个问题,如果我破坏发送者对象,message_queue 已从系统中删除,但没有通知接收者。如何解决?

如果 message_queue 在创建 MessageQueueReceiver 对象时不存在,它会抛出异常,这对我来说是正常行为,但如果我从系统 boost::interprocess::message_queue::receive 中删除 message_queue 则不会t throw anything, boost::interprocess::message_queue::timed_receive return false 但这只是意味着超时已过期。

作为解决方案,我在超时到期时抛出异常并重新创建 MessageQueueReceiver 对象。