gpt4 book ai didi

c++ - boost::asio 中的 post 和 dispatch 有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 20:51:17 30 4
gpt4 key购买 nike

我正在尝试使用 boost:asio用于创建线程池的库。官方文档说:

dispatch : Request the io_service to invoke the given handler.

post: Request the io_service to invoke the given handler and return immediately.

谁能解释一下这两者有何不同?

最佳答案

不同之处在于 dispatch 可能会在其中运行 handler(传递给它的 CompletionHandler),这意味着您将等待它完成,如果是,则在函数返回之前。另一方面,post 本身不会运行 handler 并立即返回调用站点。

因此,dispatch 是一个潜在的阻塞调用,而 post 是一个非阻塞调用。

关于c++ - boost::asio 中的 post 和 dispatch 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50911274/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com