What is the performance difference between strand::post()
and strand::wrap()
? And what's the story about race condition when use strand::wrap(
)?
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