boost::asio 阻塞卡顿问题

boost::asio 阻塞卡顿问题

在windows使用boost库 1.70.x 版本, 使用相关的asio功能, 遇到了ioservice 无法退出的情况, 经调试卡顿在 win_iocp_io_context::shutdown() 函数无法退出, 后修改了此函数

while (::InterlockedExchangeAdd(&outstanding_work_, 0) > 0)
  {
    op_queue<win_iocp_operation> ops;
    timer_queues_.get_all_timers(ops);
    ops.push(completed_ops_);
    if (!ops.empty())
    {
      while (win_iocp_operation* op = ops.front())
      {
        ops.pop();
        ::InterlockedDecrement(&outstanding_work_);
        op->destroy();
      }
    }
    else
    {
      DWORD bytes_transferred = 0;
      dword_ptr_t completion_key = 0;
      LPOVERLAPPED overlapped = 0;
      ::GetQueuedCompletionStatus(iocp_.handle, &bytes_transferred,
          &completion_key, &overlapped, gqcs_timeout_);
      if (overlapped)
      {
        ::InterlockedDecrement(&outstanding_work_);
        static_cast<win_iocp_operation*>(overlapped)->destroy();
		
	  }
	  else { break;  } // fix: add new code for quite !
    }
  

在使用 boost::asio::simple_queue 构建队列, 使用 boost::asio::queue_sender, boost::asio::queue_listener 中,
也遇到 队列不能退出, block 阻塞问题, 主要是service 中还挂载着异步io请求, 要释放这个请求。 解决的方案是:

msg 退出message
_message_queue_receiver->async_enq(msg,
boost::bind(&class_xxxx::on_receiver_default<boost::shared_ptr>, this));

在消息处理函数中 收到此消息 msg 时, 不在发起异步io请求调用, 即不再调用:

_message_queue_poster->async_deq(boost::bind(
			&class_xxxx::pickup_message, this, err, boost::placeholders::_2));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值