Note that there are some explanatory texts on larger screens.

plurals
  1. POKeeping two cross-communicating asio io_service objects busy
    text
    copied!<p>I am using boost:asio with multiple io_services to keep different forms of blocking I/O separate. E.g. I have one io_service for blocking file I/O, and another for long-running CPU-bound tasks (and this could be extended to a third for blocking network I/O, etc.) Generally speaking I want to ensure that one form of blocking I/O cannot starve the others.</p> <p>The problem I am having is that since tasks running in one io_service can post events to other io_service (e.g. a CPU-bound task may need to start a file I/O operation, or a completed file I/O operation may invoke a CPU-bound callback), I don't know how to keep both io_services running until they are both out of events.</p> <p>Normally with a single I/O service, you do something like:</p> <pre><code> shared_ptr&lt;asio::io_service&gt; io_service (new asio::io_service); shared_ptr&lt;asio::io_service::work&gt; work ( new asio::io_service::work(*io_service)); // Create worker thread(s) that call io_service-&gt;run() io_service-&gt;post(/* some event */); work.reset(); // Join worker thread(s) </code></pre> <p>However if I simply do this for both io_services, the one into which I did not post an initial event finishes immediately. And even if I post initial events to both, if the initial event on io_service B finishes before the task on io_service A posts a new event to B, io_service B will finish prematurely.</p> <p>How can I keep io_service B running while io_service A is still processing events (because one of the queued events in service A might post a new event to B), and vice-versa, while still ensuring that both io_services exit their run() methods if they are ever both out of events at the same time?</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