What is the performance difference between strand.post and strand.wrap?

丶灬走出姿态 提交于 2020-01-13 19:50:23

问题


What is the performance difference between strand::post() and strand::wrap()? And what's the story about race condition when use strand::wrap()?


回答1:


Just for clarification, strand::wrap only creates a handler, neither the provided handler nor returned handler are dispatched or posted to the io_service. If the result from strand::wrap is executed, then performance differences from overhead is negligible. However, a perceived performance difference could occur as the result of the wrapped handler using dispatch(), where under certain conditions the user's handler will be executed immediately, instead of post(), where the user's handler is always added to the queue.

Also, there should be no race conditions when using a strand. Per the documentation, it is thread safe for distinct and shared objects.



来源:https://stackoverflow.com/questions/14413054/what-is-the-performance-difference-between-strand-post-and-strand-wrap

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