Re: [Boost-users] asio - improving chat server example

Hi, John.
As you recall, I am using boost/Threads to execute io_service::run() to allow my server to have a main-thread application loop. The use of threads have complicated my application design by giving me problems to join the thread_group upon shutdown.
I just had the thought, maybe I can tickle the io_service each frame of my main-thread loop instead of using Threads? Is that the motivation for io_service::poll() ? Maybe using io_service.poll() will allow me to avoid the need for threads, at least while I'm proving the concept. What do you think?
I don't think asio::io_service::poll() can help you. The only solutions I can suggest I've described before. It isn't related to Asio - it is related to proactor pattern.
Maybe I can contribute a more interesting TCP server example if this works. :) Ideally, it would also show clean shutdown when using threads to run the io_service, but I'm not there yet.
I thought I've already done it :)
Also, I began looking at your code. Thank you for making it available. I'm a little worried it will take me as long to learn your framework as it will to learn the Asio framework.
It is not a framework. It is more like to be code snippets. Some parts are copies of Asio internals. Regards, Marat Abrarov.

On Tue, May 22, 2012 at 05:38:27PM +0400, Marat Abrarov wrote:
Hi, John.
As you recall, I am using boost/Threads to execute io_service::run() to allow my server to have a main-thread application loop. The use of threads have complicated my application design by giving me problems to join the thread_group upon shutdown.
I just had the thought, maybe I can tickle the io_service each frame of my main-thread loop instead of using Threads? Is that the motivation for io_service::poll() ? Maybe using io_service.poll() will allow me to avoid the need for threads, at least while I'm proving the concept. What do you think?
I don't think asio::io_service::poll() can help you. The only solutions I can suggest I've described before. It isn't related to Asio - it is related to proactor pattern.
If you have a soft-realtime main loop as is common in games, it's perfectly fine to invoke poll() instead of having separate threads running run(). My canonical main loop tends to be: while (1) { PeekOSMessages(); main_io.poll(); simulate(); render(); } This has the added benefit of executing in the main thread, so you don't need as much synchronization and checking for changes compared to running handlers in different threads. Personally, I have * an io_service for post()ing callbacks to the main thread, * an io_service with a bunch of worker threads for small network jobs, * an io_service with low-priority threads for bulk deferred work. This tends to cover all the workloads I encounter in a networked game client. -- Lars Viklund | zao@acc.umu.se
participants (2)
-
Lars Viklund
-
Marat Abrarov