gpt4 book ai didi

c++ - 如果发送进程停止,boost::interprocess::timed_receive() 永远不会返回

转载 作者:太空宇宙 更新时间:2023-11-04 13:55:13 25 4
gpt4 key购买 nike

我认为在这种情况下调用 timed_receive() 只会超时,但它会在尝试锁定互斥体时卡住。

那么在尝试接收数据之前,是否有一个函数可以在我的队列中调用,它会告诉我发送进程是否已终止或暂停?

最佳答案

没有通用的方法可以知道对方是死亡、停止、部分锁定(例如,其中一个线程处于无限循环中)、玩负鼠,还是只是敌对。如果对方是合作的,您可以与心跳通信并依靠它们来决定它是否响应。

您的程序在尝试锁定互斥量时“卡住”(您确定是这种情况吗?)这一事实表明,

  • 队列为空,超时值未过期
  • 您遇到了死锁情况。

timed_receive 成功、超时或按预期抛出:

bool timed_receive(void * buffer, std::size_t buffer_size,                    std::size_t & recvd_size, unsigned int & priority,                    const boost::posix_time::ptime & abs_time);

Receives a message from the message queue. The message is stored in buffer "buffer", which has size "buffer_size". The received message has size "recvd_size" and priority "priority". If the message queue is empty the receiver retries until time "abs_time" is reached. Returns true if the message has been successfully sent. Returns false if timeout is reached. Throws interprocess_error on error.

还要确保您传递了一个绝对 超时值。

关于c++ - 如果发送进程停止,boost::interprocess::timed_receive() 永远不会返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21792471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com