What is the difference between using strand :: post and io_service :: post with strand :: wrap?

In my understanding, moving handlers to the strand object means:

  • Only one of the sent handlers is executed at a time.
  • Handlers are called in order.

Sending handlers directly to the io_service object and transferring them to strand::wrap also means that only one of the sent handlers is executed at a time, but not in order.

Is there any other difference? And how can I do two (or more) different kinds of work (like different handlers / functions) in parallel (in different threads) using strand ?

+4
source share
2 answers

If you want them to run in parallel, do not use the stands. Strings are intended for serialization. Just send a message to the service and start the service in the thread pool.

But you are raising a good point that I want someone to answer. What is the difference? If wrap completes the serialization of all handlers, then how can they fail, i.e. Does it look like he is doing the same thing as posting through a chain? Where will you use one over the other?

+1
source

In fact, strand is a queue, so placing a handler in io_service on wrap is the same as not for porting, because every time you send it, you execute a different temp strand (each queue contains only one handler - all these handlers can be executed at the same time because they are not in the same strand ). If you need serialized handlers, they must be wrapped with the same strand (so it contains more than one handler).

0
source

All Articles