Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, it depends on the context of the call, i.e. is it run from within the io_service or without:
postwill not call the function directly, ever, but postpone the call.dispatchwill 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.
What this means:
… is that
dispatchmight eventually call your code again (naturally, this depends on your app and how you chain calls), but in general you should make sure your callback is re-entrant if you usedispatch.dispatchis thus faster, as it avoids queueing the call if possible. It comes with some caveats, so you might want needs to usepostoccasionally, or always (if you want to play it safe and can afford it).Update
To incorporate some from @gimpf ‘s deleted answer, an older boost version had this implementation of dispatch (my comments):