【问题标题】:boost::interprocess message queue timed_receive() internal procedureboost::interprocess 消息队列 timed_receive() 内部过程
【发布时间】:2020-11-17 23:40:12
【问题描述】:

我目前使用 boost::interprocess 库中的 timed_receive() 方法来接收数据。由于收到消息的时间会有所不同,我在 receive() 方法上使用了这个方法。

msgque->timed_receive((void*) &message,sizeof(int),recvd_size,priority,
            boost::posix_time::ptime(microsec_clock::universal_time()) + boost::posix_time::milliseconds(300))

问题: 此方法如何知道缓冲区中存在消息?是轮询机制还是实现了更复杂的机制? 我阅读了文档并找不到任何详细信息,并且源代码也没有提供任何信息。

已经谢谢了。

【问题讨论】:

    标签: c++ boost message-queue


    【解决方案1】:

    这个库不需要记录它是如何工作的,因为那是一个实现细节。理想情况下,您不需要知道,这就是您首先使用库的原因。

    您可以期望该库根据更原始的库构建块来实现它:

    这意味着条件由另一个进程发出信号。

    但是,也有可能在给定平台上使用更高级/更专业的东西(请参阅https://unix.stackexchange.com/questions/6930/how-is-a-message-queue-implemented-in-the-linux-kernel)。

    对源代码的快速扫描确认了使用库中的构建块在第一原则上的直接实现:

    //Mutex to protect data structures
    interprocess_mutex         m_mutex;
    //Condition block receivers when there are no messages
    interprocess_condition     m_cond_recv;
    //Condition block senders when the queue is full
    interprocess_condition     m_cond_send;
    #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
    //Current start offset in the circular index
    size_type                  m_cur_first_msg;
    size_type                  m_blocked_senders;
    size_type                  m_blocked_receivers;
    #endif
    

    广泛的内嵌文档。如果您想了解更多信息,建议您仔细阅读。

    【讨论】:

    • Fixed 格式错误。对此感到抱歉。
    猜你喜欢
    • 2021-04-20
    • 2021-09-24
    • 2019-04-08
    • 2014-03-04
    • 1970-01-01
    • 2013-03-10
    • 2021-05-19
    • 2019-05-01
    • 2011-03-26
    相关资源
    最近更新 更多