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

标签 c++ winapi boost boost-interprocess

我认为在这种情况下调用 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/

相关文章:

c++ - 如何将库添加到eclipse中

c++ - 资源图像不工作 C++

c++ - 使用 GLFW 渲染和 WinAPI 处理消息

c++ - 对 BOOST::ASIO 中的单个解析器使用不同查询对象的多个 async_resolve 调用是否正常?

c++ - Boost last_write_time 更改最后写入时间值

c++ - 将 C++ Win32 应用程序移植到 linux 应用程序

c++ - 0x771CC7C9 (ntdll.dll) 处未处理的异常

c++ - 子窗口不显示

c++ - 需要使用互斥量显式定义复制构造函数

c++ - C++ 中的自定义 list.sort 比较