Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <strong>Boost.Asio</strong> docs:</p> <blockquote> <p>The io_service::strand class provides the ability to post and dispatch handlers with the guarantee that none of those handlers will execute concurrently.</p> </blockquote> <p>There's <a href="http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3" rel="nofollow">a good example</a> of <code>strand</code> usage in <strong>Boost.Asio</strong> examples.</p> <p><code>strand</code> guarantees that your handler execution will be synchronized. That means that <code>strand</code> is useful if your <code>io_service</code> is executed from multiple threads. It's not related to how you schedule your tasks (handlers).</p> <p><code>strand</code> cannot help you to do multiple socket read or write ops concurrently, because internal read/write execution cannot be done concurrently, so there should be just one active read or write async op. </p> <p>For <code>reads</code> you just call <code>async_read</code> to initiate read sequence and call it again from your read handler after consuming received data. The same that you do in single threaded environment. </p> <p>For <code>writes</code> if there're concurrent producers (if multiple threads provides data to be written to socket) you need a concurrent queue (e.g. <a href="http://www.boost.org/doc/libs/1_47_0/libs/circular_buffer/doc/circular_buffer.html#examples" rel="nofollow">boost circular buffer</a>, look for "Bounded Buffer Example"). Your write function takes data from this buffer and async writes it to socket. Your write handler invokes your write function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload