首页 > 解决方案 > 为什么多个 boost::io_services 会阻塞主线程?

问题描述

我有一个需要从 7 个串行端口读取的应用程序。我创建了一个封装串行端口并打开 boost::asio::serial_port 并启动异步读取操作的类。我正在接收我的所有数据,但是 io_service 线程占用了大量 CPU 时间并减慢了我的主线程。有什么方法可以阻止 io_service 线程使用这么多 CPU 时间?

标签: c++boost

解决方案


一些伪代码:

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 )

推荐阅读