Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's exactly the difference between using strand::post and io_service::post with strand::wrap?

In my understanding, posting handlers to a strand object means:

  • Only one of the posted handlers is executed at a time.
  • The handlers are invoked in order.

Posting handlers directly to an io_service object and wrapping them by strand::wrap also means that only one of the posted handlers is executed at a time, but not in order.

Is there any other difference? And how can I run two (or more) different kind of works (so, different handlers/functions) parallel (in different threads) by using strand?

like image 263
0xbadf00d Avatar asked Nov 13 '22 16:11

0xbadf00d


1 Answers

If you want them to run in parallel don't use stands. Strands are for serializing. Just post to the service and have the service run in a thread pool.

But you bring up a good point that I would like someone to answer. What exactly is the difference? If wrap serializes all handlers then how could they get out of order, i.e. seems like it does the same thing as posting through a strand? Where would you use one over the other?

like image 153
Oliver K Avatar answered Dec 18 '22 12:12

Oliver K