What does inside the strand mean?

I'm currently trying to take on the threads boost::asio. By doing this, I continue to read about "calling strand post/dispatchinside or outside the string." One way or another, I cannot understand how the inside of the strand is different from the thread, and therefore cannot understand the concept of calling the strand function outside the thread in general.

There is probably a small piece in my puzzle. Can someone please give an example of how calls to a strand can be inside or outside?

I think I still understood that posting something through a chain would

m_strand.post(myfunctor);

or

m_strand.wrap(myfunctor);
io_svc.post(myfunctor); 

Is the latter considered a call dispatchoutside the line (unlike the other, which is a call postinside it)? Is there any connection between the threads "within the kingdom" and the flows on which the strand acts?

If inside the line is just meant to call the strand function, then strand class documentation would be pointless. It says that strand::postyou can call outside the strand ... It is this part that I do not understand.

+4
source share
2 answers

strand s, s , s.running_in_this_thread() false. true, , post(), dispatch() wrap(). false:

io_service.post(handler);              // handler will run outside of strand
strand.post(handler);                  // handler will run inside of strand
strand.dispatch(handler);              // handler will run inside of strand
io_service.post(strand.wrap(handler)); // handler will run inside of strand

:

  • strand s
  • f1, s s.post() s.dispatch(), s.running_in_this_thread() == false
  • f2, s s.post() s.dispatch(), s.running_in_this_thread() == false

concurrency, f1 f2 . , f1 f2, f1 f2.

+2

, , libdispatch. asio.

, strand. strand handlers, .

, ? worker.

? io_service, , . - :

asio::strand s(io_serv_obj);

, , io_service::run . , run io_serv_obj, . , .

, post , , . .

, dispatch, asio :

  • , - (, io_service). , , outside the strand. , outside , , post, , , , .

UPDATE: , inside called within another handler i.e, : A , dispatch . , № 2, , . , , dispatch outside.

  1. , dispatch outside , , asio callstack, , - , . , . , ( , , , ).

:

s.dispatch(a) - s.post(b),

, dispatch - run OR, , , , . , A b.

s.dispatch(c) a b, A b ( ) , c A b, b A.

, .

+8

All Articles