何时在asio中使用异步操作

时间:2022-02-23 21:04:13

When should I use asynchronous operations in boost::asio instead of synchronous operations in seperate threads?

我应该何时在boost :: asio中使用异步操作而不是在单独的线程中进行同步操作?

2 个解决方案

#1


I would strongly urge you to use a asynchronous approach whenever possible. A asynchronous call doesn't necessarily create a thread, so by sticking with an asynchronous operation you may reduce the overhead that is associated with threads. In addition threads are usually harder to develop and maintain.

我强烈建议您尽可能使用异步方法。异步调用不一定会创建一个线程,因此通过坚持异步操作,您可以减少与线程相关的开销。此外,线程通常更难开发和维护。

Hope it helps.

希望能帮助到你。

#2


Does the Rationale section help?

理由部分有帮助吗?

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development.

大多数程序以某种方式与外部世界交互,无论是通过文件,网络,串行电缆还是控制台。有时,与网络一样,单个I / O操作可能需要很长时间才能完成。这对应用程序开发提出了特殊挑战。

Boost.Asio provides the tools to manage these long running operations, without requiring programs to use concurrency models based on threads and explicit locking.

Boost.Asio提供了管理这些长时间运行操作的工具,而无需程序使用基于线程和显式锁定的并发模型。

#1


I would strongly urge you to use a asynchronous approach whenever possible. A asynchronous call doesn't necessarily create a thread, so by sticking with an asynchronous operation you may reduce the overhead that is associated with threads. In addition threads are usually harder to develop and maintain.

我强烈建议您尽可能使用异步方法。异步调用不一定会创建一个线程,因此通过坚持异步操作,您可以减少与线程相关的开销。此外,线程通常更难开发和维护。

Hope it helps.

希望能帮助到你。

#2


Does the Rationale section help?

理由部分有帮助吗?

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development.

大多数程序以某种方式与外部世界交互,无论是通过文件,网络,串行电缆还是控制台。有时,与网络一样,单个I / O操作可能需要很长时间才能完成。这对应用程序开发提出了特殊挑战。

Boost.Asio provides the tools to manage these long running operations, without requiring programs to use concurrency models based on threads and explicit locking.

Boost.Asio提供了管理这些长时间运行操作的工具,而无需程序使用基于线程和显式锁定的并发模型。