c++ - 为什么多个 boost::io_services 会阻塞主线程?
问题描述
我有一个需要从 7 个串行端口读取的应用程序。我创建了一个封装串行端口并打开 boost::asio::serial_port 并启动异步读取操作的类。我正在接收我的所有数据,但是 io_service 线程占用了大量 CPU 时间并减慢了我的主线程。有什么方法可以阻止 io_service 线程使用这么多 CPU 时间?
解决方案
一些伪代码:
construct io_service
for each port
open port
start async read ( register read_handler_for_port )
run io_service
read_handler_for_port ()
handle data
start async read ( register read_handler_for_port )
推荐阅读
- python - 冒号运算符导致 Python 3.4 和 Ubuntu 14.04 出现问题
- javascript - Vue Js:如何在单独的 js 文件中分离“方法”、“数据”、“计算”等
- java - 尝试将私钥和公钥转换为字符串格式
- c++ - SendMessage WM_SETTEXT 在 MFC 应用程序的另一个应用程序上不起作用
- android - 显示/隐藏应用栏会导致主内容窗口出现不良移动/动画
- c# - 有没有办法通过引用比较 2 个 ref 结构?
- python - 使用 PyGame 检测两个精灵是否重叠
- vb.net - 将集合作为数据源传递给 vb.net 2015 中的图表
- swift - Swift:当设备以横向启动时,约束不正确
- javascript - TypeError:无法在 EventEmitter 读取未定义的属性“应用”