Using boost::asio thread pool for general purpose tasks

大城市里の小女人 提交于 2019-11-27 20:17:33

Boost.Asio is not solely for network programming, see the reference documentation. It has extensive support for things like

  • time based operations (deadline_timer)
  • signal handling
  • platform specific operations such as posix streams and Windows handles

I've used it for other purposes in several applications as well. One example being a thread pool to service potentially long running blocking database operations while providing an asynchronous interface for the application. Boost.Asio really is a very powerful library. Using it for a general purpose thread pool as you propose can work just fine.

I don't see any reason not to do things this way. As a benefit, you can use things like deadline timers which are built on top of boost::asio.

I wrote a ThreadPool class with boost asio. It works and it is clean &clear enough to understand easily. ThreadPool with boost asio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!