提高ASIO io_service对象调度VS岗位 [英] Boost asio io_service dispatch vs post

查看:172
本文介绍了提高ASIO io_service对象调度VS岗位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我io_service对象的派遣的?目前尚不清楚对我有什么更适合我的问题。

Can anyone tell me the difference between io_service dispatch and post? It was not clear to me what is more suitable for my problem.

我需要调用另一个处理程序中的处理程序,我不知道是什么的调用的使用。

I need to invoke a handler inside another handler and I don't know what invoker to use.

推荐答案

嗯,这取决于呼叫的情况下,即是从io_service对象内或不运行:

Well, it depends on the context of the call, i.e. is it run from within the io_service or without:


  • 将不直接调用功能,前所未有,但推迟了电话。

  • 调度将其称之为rightaway如果调度,来电者是从io_service对象本身的调用,但除此之外,它排队。

  • post will not call the function directly, ever, but postpone the call.
  • dispatch will call it rightaway if the dispatch-caller was called from io_service itself, but queue it otherwise.

所以,这取决于函数调用后/调度叫了,如果给定的处理器可以马上或不叫。

So, it depends on the function calling post/dispatch was called, and if the given handler can be called straight away or not.

这意味着什么:

...是调度可能最终会打电话给你的code再次(当然,这取决于你的应用程序,你是如何调用链),但一般而言,您应如果您使用的确保你的code /对象/函数重入调度

... is that dispatch might eventually call your code again (naturally, this depends on your app and how you chain calls), but in general you should make sure your code/object/function is re-entrant if you use dispatch.

调度因此速度更快,因为它避免了排队如果可能的话通话。它配备了一些注意事项,所以你可能要需要使用偶尔或经常(如果你想发挥它的安全,并能负担得起)。

dispatch is thus faster, as it avoids queueing the call if possible. It comes with some caveats, so you might want needs to use post occasionally, or always (if you want to play it safe and can afford it).

更新

要加入一些从@gimpf的答案被删除,一个旧版本的提升有这个执行调度(我的意见):

To incorporate some from @gimpf 's deleted answer, an older boost version had this implementation of dispatch (my comments):

template <typename Handler>
void dispatch(Handler handler)
{
  if (call_stack<win_iocp_io_service>::contains(this))
    boost_asio_handler_invoke_helpers::invoke(handler, &handler); // call
  else
    post(handler); // queue
}

这篇关于提高ASIO io_service对象调度VS岗位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆