[ASIO] permanently blocked io_service.run()
Hello, I have setup a multithreaded application with multiple io_service objects because I want to pick out the thread that executes a particular event handler. So each thread object will have a copy of their own io_service object. The main server object (who handles accepts) picks which thread executes an event handler. I hope that makes sense. Anyways the main run function of the thread object will have to call io_service.run() so that it can execute the event handlers that the server object sets up for it. My question is how do I keep the thread's io_service.run() from returning right away, since there will be no work for the io_service.run() to do until the server lines up a new connection for the thread to handle? I came up with ways to do this using deadline_timer_service.async_wait(), where the thread calls async_wait() and the event handler for the async_wait() just calls another async_wait(). This should keep work for the io_service.run() to do and permanently blocked but I find this approach quite hackish. But for all I know this could be why deadline_timer_service was created for. Any thoughts on a more elegant way of doing this? thanks jose "survival first, then happiness as we can manage it"
My question is how do I keep the thread's io_service.run() from returning right away, since there will be no work for the io_service.run() to do until the server lines up a new connection for the thread to handle?
Use asio::io_service::work class: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/io_servic... Look at the following example for details: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/example/http/server...
participants (2)
-
Igor R
-
Jose Martinez